1
00:00:00,740 --> 00:00:01,910
In this video.

2
00:00:01,940 --> 00:00:04,280
Let's talk about find.

3
00:00:06,700 --> 00:00:06,870
Okay.

4
00:00:07,000 --> 00:00:11,290
So let me comment this one out and then comment out these ones.

5
00:00:11,500 --> 00:00:19,360
So find is also one of the array methods that we often use most at times.

6
00:00:19,840 --> 00:00:22,900
So let's see what does find mean?

7
00:00:22,900 --> 00:00:31,240
If you get back to MongoDB, you understand what find is about MongoDB find is in contrast with find

8
00:00:31,240 --> 00:00:32,470
in JavaScript.

9
00:00:32,470 --> 00:00:34,690
So let's see what find means.

10
00:00:34,690 --> 00:00:41,020
Well, as the name implies, it is used to find element in an array list.

11
00:00:41,020 --> 00:00:42,010
I want to find.

12
00:00:42,010 --> 00:00:47,200
For the meantime let's declare variable cons as edges.

13
00:00:47,290 --> 00:00:53,890
Edges array is equal to we have ten years, ten years.

14
00:00:53,890 --> 00:00:55,630
We have 20 years.

15
00:00:55,810 --> 00:00:59,590
We have 30 years, we have 50 years.

16
00:00:59,590 --> 00:01:03,370
And we have let's say, I mean 24 years.

17
00:01:03,880 --> 00:01:04,480
Okay.

18
00:01:04,690 --> 00:01:16,870
So here we can I can ask you that place in this array, find me all the edges that is less than 20 years

19
00:01:16,870 --> 00:01:17,980
in this array.

20
00:01:18,220 --> 00:01:18,730
Right?

21
00:01:18,730 --> 00:01:29,110
So I'm going to use fine to make this happen, but find also execute a function for every array element.

22
00:01:29,590 --> 00:01:38,890
So it's always retained undefined if there is no matching element in your search criteria or in your

23
00:01:38,890 --> 00:01:39,490
logic.

24
00:01:39,880 --> 00:01:44,920
And one more time the fine method does not mutate the original array.

25
00:01:45,100 --> 00:01:46,030
So let's see.

26
00:01:46,810 --> 00:01:53,800
So let's say that for this I want to find all edges less than 20.

27
00:01:53,980 --> 00:01:54,880
So here we go.

28
00:01:55,000 --> 00:02:03,370
The same process for I mean, for reduce the same syntax for the meantime, let's also write the syntax

29
00:02:03,370 --> 00:02:12,430
here, the array dot find and as a function here, the same process you pass in a callback function

30
00:02:13,150 --> 00:02:13,840
as that.

31
00:02:13,840 --> 00:02:17,380
But for this one it takes only one element online.

32
00:02:17,380 --> 00:02:21,280
They reduce, they pass in another argument.

33
00:02:21,310 --> 00:02:30,460
So here for this one, we have the actual I mean, data that can make as data or record.

34
00:02:30,460 --> 00:02:36,790
So this what I find here represent the individual data inside the array.

35
00:02:36,790 --> 00:02:41,170
So this one represents the individual records in this particular array.

36
00:02:41,830 --> 00:02:43,540
So here and that is it.

37
00:02:43,540 --> 00:02:48,160
Then you can make your logic routine, whether it is more than $2 and four.

38
00:02:48,610 --> 00:02:49,930
So here you go.

39
00:02:50,110 --> 00:02:51,670
So this is a syntax.

40
00:02:52,890 --> 00:02:54,000
Sin.

41
00:02:56,260 --> 00:02:56,920
Tax.

42
00:02:57,070 --> 00:02:57,790
Perfect.

43
00:02:57,790 --> 00:02:58,870
So now let's see.

44
00:02:58,870 --> 00:03:01,960
So let's say that find.

45
00:03:03,620 --> 00:03:04,400
H.

46
00:03:06,810 --> 00:03:08,400
Less than.

47
00:03:09,700 --> 00:03:10,630
Hmm.

48
00:03:10,660 --> 00:03:12,940
Three years in this area.

49
00:03:12,970 --> 00:03:14,680
How are you going to do it?

50
00:03:15,130 --> 00:03:16,270
So the same process.

51
00:03:16,270 --> 00:03:26,080
I would take my ages array to find and then find as a function pass in my callback function parentheses

52
00:03:26,080 --> 00:03:27,520
and my carry braces.

53
00:03:27,790 --> 00:03:28,630
Here we go.

54
00:03:29,020 --> 00:03:32,860
So here we have access to the individual record in this array.

55
00:03:32,890 --> 00:03:35,560
Then I can represent this one with a variable.

56
00:03:35,590 --> 00:03:37,630
It can be any.

57
00:03:37,660 --> 00:03:40,210
It can be whatever.

58
00:03:40,240 --> 00:03:42,430
It can be foo.

59
00:03:42,940 --> 00:03:43,630
Those.

60
00:03:43,630 --> 00:03:48,430
This one represent the actual data in the.

61
00:03:49,740 --> 00:03:51,710
The individual data in the array.

62
00:03:51,720 --> 00:03:58,210
So if I cancel that log foo see that I get them here.

63
00:03:58,710 --> 00:04:04,640
First one is ten, 20, 30, 50 and 24.

64
00:04:04,650 --> 00:04:16,320
So now when I get it back I can nine return and see that well find it is less than 30 so you can see

65
00:04:16,320 --> 00:04:20,579
that fus let me see h h here.

66
00:04:20,760 --> 00:04:22,740
So I would say h.

67
00:04:23,690 --> 00:04:25,820
Less than 30.

68
00:04:26,690 --> 00:04:27,650
Do we have some?

69
00:04:28,010 --> 00:04:31,100
So we do have some record that are less than 30.

70
00:04:31,130 --> 00:04:34,000
Yes, we have 20 and 30.

71
00:04:34,010 --> 00:04:36,140
So let's see if I'm going to get this one.

72
00:04:36,140 --> 00:04:41,330
But this record data are not less than what I mean 30.

73
00:04:41,360 --> 00:04:46,250
So it will not display this.

74
00:04:46,250 --> 00:04:48,230
So let's assign the results.

75
00:04:49,820 --> 00:04:54,140
So a cost, let's say, result equal to that.

76
00:04:54,560 --> 00:04:59,240
So down here, let's consider that look the result.

77
00:05:01,720 --> 00:05:02,250
Okay.

78
00:05:02,530 --> 00:05:03,240
You see that?

79
00:05:03,250 --> 00:05:05,020
I get ten.

80
00:05:05,990 --> 00:05:13,220
Guys, you see some weird things here, even though I have 20 here, but it's not retained that.

81
00:05:14,070 --> 00:05:17,160
If I remove ten, let's see.

82
00:05:17,340 --> 00:05:18,510
I get 20.

83
00:05:19,690 --> 00:05:30,430
So the takeaway here is that find retain a single value that matches our criteria.

84
00:05:31,310 --> 00:05:40,160
Again find retains a single value or the first matching value based on our criteria.

85
00:05:40,730 --> 00:05:45,710
And our criteria here is, is that the age must be less than 30.

86
00:05:46,010 --> 00:05:50,930
So if I bring let's save in two years here is going to return what?

87
00:05:50,930 --> 00:05:53,870
And I bring five here and then six year.

88
00:05:54,080 --> 00:06:01,670
All these ages are less than 30, but it's going to return the first one that matches because this one

89
00:06:01,870 --> 00:06:08,420
when looking through as soon as he saw this one and it matches our logic here, logic here is going

90
00:06:08,420 --> 00:06:09,230
to return it.

91
00:06:09,470 --> 00:06:18,650
So if I save this one, I see two that is going to bear in mind about find the next video.

92
00:06:19,100 --> 00:06:22,370
Let's say that we want to find all matching criteria.

93
00:06:22,400 --> 00:06:24,380
How are we going to do it?

94
00:06:24,560 --> 00:06:28,160
That's why we talk about another method called filter.

