In this video.
Let's talk about find.
Okay.
So let me comment this one out and then comment out these ones.
So find is also one of the array methods that we often use most at times.
So let's see what does find mean?
If you get back to MongoDB, you understand what find is about MongoDB find is in contrast with find
in JavaScript.
So let's see what find means.
Well, as the name implies, it is used to find element in an array list.
I want to find.
For the meantime let's declare variable cons as edges.
Edges array is equal to we have ten years, ten years.
We have 20 years.
We have 30 years, we have 50 years.
And we have let's say, I mean 24 years.
Okay.
So here we can I can ask you that place in this array, find me all the edges that is less than 20 years
in this array.
Right?
So I'm going to use fine to make this happen, but find also execute a function for every array element.
So it's always retained undefined if there is no matching element in your search criteria or in your
logic.
And one more time the fine method does not mutate the original array.
So let's see.
So let's say that for this I want to find all edges less than 20.
So here we go.
The same process for I mean, for reduce the same syntax for the meantime, let's also write the syntax
here, the array dot find and as a function here, the same process you pass in a callback function
as that.
But for this one it takes only one element online.
They reduce, they pass in another argument.
So here for this one, we have the actual I mean, data that can make as data or record.
So this what I find here represent the individual data inside the array.
So this one represents the individual records in this particular array.
So here and that is it.
Then you can make your logic routine, whether it is more than $2 and four.
So here you go.
So this is a syntax.
Sin.
Tax.
Perfect.
So now let's see.
So let's say that find.
H.
Less than.
Hmm.
Three years in this area.
How are you going to do it?
So the same process.
I would take my ages array to find and then find as a function pass in my callback function parentheses
and my carry braces.
Here we go.
So here we have access to the individual record in this array.
Then I can represent this one with a variable.
It can be any.
It can be whatever.
It can be foo.
Those.
This one represent the actual data in the.
The individual data in the array.
So if I cancel that log foo see that I get them here.
First one is ten, 20, 30, 50 and 24.
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
that fus let me see h h here.
So I would say h.
Less than 30.
Do we have some?
So we do have some record that are less than 30.
Yes, we have 20 and 30.
So let's see if I'm going to get this one.
But this record data are not less than what I mean 30.
So it will not display this.
So let's assign the results.
So a cost, let's say, result equal to that.
So down here, let's consider that look the result.
Okay.
You see that?
I get ten.
Guys, you see some weird things here, even though I have 20 here, but it's not retained that.
If I remove ten, let's see.
I get 20.
So the takeaway here is that find retain a single value that matches our criteria.
Again find retains a single value or the first matching value based on our criteria.
And our criteria here is, is that the age must be less than 30.
So if I bring let's save in two years here is going to return what?
And I bring five here and then six year.
All these ages are less than 30, but it's going to return the first one that matches because this one
when looking through as soon as he saw this one and it matches our logic here, logic here is going
to return it.
So if I save this one, I see two that is going to bear in mind about find the next video.
Let's say that we want to find all matching criteria.
How are we going to do it?
That's why we talk about another method called filter.