Let's see how we can attract over an array.
Meaning, how can we get the individual records in this array separately?
So let's get started.
So let me comment out these ones and then I may bring up bring out my book here.
Let me comment that one.
And then going to place the arrays here because I'm going to work on it.
So here is going to be going to be as what?
I'd written.
Over.
And every.
Meaning, how can we get an individual cross in the area?
And remember, we have couple of ways of doing it, but because we have been talking about I mean,
a lot of the the looping techniques like for each map and you talked about so far the for loop.
So let's use for a loop to loop through this record and get it individual I mean, data in this particular
area.
So here we go.
So I'll make use of four and then I will say let's initial value I suppose to be zero and my semicolon
like that.
So if I is less than what.
Here is a clue when we say when I is less than two.
Let's try this one for see.
Then I want to increase I plus plus.
In that way I can go ahead and then console dot log console log the I this a normal loop.
Okay, so let me save it and let's see.
Okay, I get some syntax error here.
So for four left I equal to zero and then I might be less than two A's I plus plus.
Not one plus plus.
Yes, you could say that.
We got what.
Zero and one, because here the starting point is zero, meaning that if I is less than two, then the
loop will go for the first time and then it will display the I, which is zero here.
Then we got it here.
Then on the second loop because we have increased ie here behind the scene, I has become one here so
it's going to loop again.
Now the ie this one has become what has become to add a third loop, right?
So the third loop, this one is two.
Is two less than two?
No, there is two or equal to two.
So the loop will stop.
So if I want to get the record here, remember that we use the index of the array to get the record
from it.
And here we are able to get the first index, which is zero, meaning that I can get this one and then
I can get this one using this dynamic.
Sorry, this one rather.
I made a mistake.
The first one is this one.
The first one I can get the index zero and the second one I can get this one.
So what about this one?
Okay, so with this one, let's try to get the record inside here.
So we are going to take the array here, the array.
So I would take the books array.
Then if I try to say I want the first zero here, let's console.log, that let's console.log, or we
can assign to a variable core as array like that.
Then I can console that, log the array like that.
So you see that I get MongoDB that has appeared two times.
We have X or K two time because the loop has I mean go over to times and we have two times over here.
So what about I want this one more dynamic, not always passing in this, but instead I want to get
the values from the loop and pass in here.
So if I pass in, I hear this, I can be zero or one.
Okay, so if I save it, let's check out if I save this one.
Now I have got the variables, the data inside my array as MongoDB and Node.js.
But what about this one?
The rest of the React and then JavaScript here they react also here.
So because we don't know for the meantime, you can count.
Okay, we have zero one, two, three.
So here you can see that three here.
Now we get new.
We get all the sorry guys.
Now you got the all the record that has been displayed.
What about in future?
If we update this particular array and app, let's say I want add a main to it.
Unless I come back.
I didn't get a table here because here is less than three.
Okay.
So in the future, let's say we've added this one unless I come again to my loop here and then say,
oh, now we have one, one, two, three, four.
So how to make here?
As for you see, we are making our life difficult.
So let's make this value dynamic by getting the length of this.
We haven't talked about how to get the total length of setting array, but we have a method called length,
meaning that if you if you want to get a total length of this book here for the meantime, let me comment
out this one.
And now I want to know how many records are in this array.
So here, I mean, check for how many.
Real costs in this area.
And we have a method for that.
And we dive in more about three methods.
For the meantime, let's solve this one.
So we have, let's say, cons as to water to water record.
Is equal to.
I would take the books and on that half length.
So if I console.log the the total record.
Are we able to know I have four records in the array.
One, two, three, four, go.
So now if I add a record to it, let's say six and I save it, you see that I got five.
So we are going to use this technique here inside our for loop so that it can be dynamic.
So now coming back here, let me remove this one and now let me uncomment this one.
So here is going to be the total record here.
Like this one.
So if I save it, you see that I get all the record.
So in future, if I add in the record, whatever, let's say what books I add into it, let's say I
want to add Angular.
Now I get Angular being displayed.
So this is more dynamic.
So but by convention, we normally write everything in line than this one as a variable.
Get a lamp and a reference ID here so we can quickly do it in line as books dot length.
Yes, it is shorter.
It is easier like that.
So it is how we are able to look through an array and get a record in it.
The next video we will talk about some of the array methods and then after that we will start with our
coding challenge.