1
00:00:00,670 --> 00:00:04,710
Let's see how we can attract over an array.

2
00:00:04,720 --> 00:00:10,540
Meaning, how can we get the individual records in this array separately?

3
00:00:10,570 --> 00:00:11,620
So let's get started.

4
00:00:11,620 --> 00:00:17,440
So let me comment out these ones and then I may bring up bring out my book here.

5
00:00:17,470 --> 00:00:18,910
Let me comment that one.

6
00:00:18,910 --> 00:00:22,810
And then going to place the arrays here because I'm going to work on it.

7
00:00:22,900 --> 00:00:28,540
So here is going to be going to be as what?

8
00:00:30,070 --> 00:00:31,360
I'd written.

9
00:00:32,350 --> 00:00:33,220
Over.

10
00:00:33,860 --> 00:00:35,480
And every.

11
00:00:37,270 --> 00:00:40,720
Meaning, how can we get an individual cross in the area?

12
00:00:40,750 --> 00:00:46,840
And remember, we have couple of ways of doing it, but because we have been talking about I mean,

13
00:00:46,840 --> 00:00:53,950
a lot of the the looping techniques like for each map and you talked about so far the for loop.

14
00:00:54,100 --> 00:01:01,030
So let's use for a loop to loop through this record and get it individual I mean, data in this particular

15
00:01:01,030 --> 00:01:01,600
area.

16
00:01:01,630 --> 00:01:03,220
So here we go.

17
00:01:03,460 --> 00:01:12,910
So I'll make use of four and then I will say let's initial value I suppose to be zero and my semicolon

18
00:01:12,910 --> 00:01:13,720
like that.

19
00:01:13,720 --> 00:01:17,140
So if I is less than what.

20
00:01:17,170 --> 00:01:21,730
Here is a clue when we say when I is less than two.

21
00:01:21,940 --> 00:01:23,860
Let's try this one for see.

22
00:01:24,070 --> 00:01:28,300
Then I want to increase I plus plus.

23
00:01:28,300 --> 00:01:39,160
In that way I can go ahead and then console dot log console log the I this a normal loop.

24
00:01:39,190 --> 00:01:41,050
Okay, so let me save it and let's see.

25
00:01:41,590 --> 00:01:44,680
Okay, I get some syntax error here.

26
00:01:45,040 --> 00:01:55,090
So for four left I equal to zero and then I might be less than two A's I plus plus.

27
00:01:55,090 --> 00:01:56,610
Not one plus plus.

28
00:01:56,620 --> 00:01:58,990
Yes, you could say that.

29
00:01:59,290 --> 00:02:00,460
We got what.

30
00:02:01,320 --> 00:02:11,790
Zero and one, because here the starting point is zero, meaning that if I is less than two, then the

31
00:02:11,790 --> 00:02:18,380
loop will go for the first time and then it will display the I, which is zero here.

32
00:02:18,390 --> 00:02:19,920
Then we got it here.

33
00:02:20,220 --> 00:02:29,010
Then on the second loop because we have increased ie here behind the scene, I has become one here so

34
00:02:29,010 --> 00:02:31,500
it's going to loop again.

35
00:02:31,710 --> 00:02:38,730
Now the ie this one has become what has become to add a third loop, right?

36
00:02:38,730 --> 00:02:42,690
So the third loop, this one is two.

37
00:02:43,610 --> 00:02:45,110
Is two less than two?

38
00:02:45,210 --> 00:02:48,210
No, there is two or equal to two.

39
00:02:48,230 --> 00:02:49,640
So the loop will stop.

40
00:02:50,000 --> 00:03:00,770
So if I want to get the record here, remember that we use the index of the array to get the record

41
00:03:00,770 --> 00:03:01,190
from it.

42
00:03:01,190 --> 00:03:09,260
And here we are able to get the first index, which is zero, meaning that I can get this one and then

43
00:03:09,260 --> 00:03:12,320
I can get this one using this dynamic.

44
00:03:12,320 --> 00:03:14,450
Sorry, this one rather.

45
00:03:14,480 --> 00:03:15,590
I made a mistake.

46
00:03:15,650 --> 00:03:17,630
The first one is this one.

47
00:03:17,630 --> 00:03:22,610
The first one I can get the index zero and the second one I can get this one.

48
00:03:22,610 --> 00:03:23,810
So what about this one?

49
00:03:24,300 --> 00:03:28,820
Okay, so with this one, let's try to get the record inside here.

50
00:03:28,880 --> 00:03:35,060
So we are going to take the array here, the array.

51
00:03:35,180 --> 00:03:37,310
So I would take the books array.

52
00:03:37,340 --> 00:03:44,930
Then if I try to say I want the first zero here, let's console.log, that let's console.log, or we

53
00:03:44,930 --> 00:03:49,430
can assign to a variable core as array like that.

54
00:03:49,460 --> 00:03:54,740
Then I can console that, log the array like that.

55
00:03:54,740 --> 00:03:59,450
So you see that I get MongoDB that has appeared two times.

56
00:03:59,450 --> 00:04:06,770
We have X or K two time because the loop has I mean go over to times and we have two times over here.

57
00:04:06,980 --> 00:04:13,190
So what about I want this one more dynamic, not always passing in this, but instead I want to get

58
00:04:13,190 --> 00:04:15,950
the values from the loop and pass in here.

59
00:04:16,519 --> 00:04:21,390
So if I pass in, I hear this, I can be zero or one.

60
00:04:21,470 --> 00:04:25,940
Okay, so if I save it, let's check out if I save this one.

61
00:04:26,330 --> 00:04:33,050
Now I have got the variables, the data inside my array as MongoDB and Node.js.

62
00:04:33,140 --> 00:04:34,340
But what about this one?

63
00:04:34,340 --> 00:04:39,440
The rest of the React and then JavaScript here they react also here.

64
00:04:39,470 --> 00:04:43,460
So because we don't know for the meantime, you can count.

65
00:04:43,460 --> 00:04:46,430
Okay, we have zero one, two, three.

66
00:04:46,430 --> 00:04:48,470
So here you can see that three here.

67
00:04:49,010 --> 00:04:51,470
Now we get new.

68
00:04:51,890 --> 00:04:54,080
We get all the sorry guys.

69
00:04:54,860 --> 00:04:59,120
Now you got the all the record that has been displayed.

70
00:04:59,210 --> 00:05:01,190
What about in future?

71
00:05:01,220 --> 00:05:08,240
If we update this particular array and app, let's say I want add a main to it.

72
00:05:09,150 --> 00:05:10,320
Unless I come back.

73
00:05:10,560 --> 00:05:13,830
I didn't get a table here because here is less than three.

74
00:05:14,330 --> 00:05:14,870
Okay.

75
00:05:14,880 --> 00:05:21,750
So in the future, let's say we've added this one unless I come again to my loop here and then say,

76
00:05:21,750 --> 00:05:24,910
oh, now we have one, one, two, three, four.

77
00:05:24,930 --> 00:05:25,890
So how to make here?

78
00:05:25,890 --> 00:05:29,580
As for you see, we are making our life difficult.

79
00:05:29,670 --> 00:05:36,060
So let's make this value dynamic by getting the length of this.

80
00:05:36,180 --> 00:05:43,560
We haven't talked about how to get the total length of setting array, but we have a method called length,

81
00:05:43,560 --> 00:05:50,550
meaning that if you if you want to get a total length of this book here for the meantime, let me comment

82
00:05:50,550 --> 00:05:51,600
out this one.

83
00:05:52,020 --> 00:05:55,530
And now I want to know how many records are in this array.

84
00:05:55,530 --> 00:06:02,250
So here, I mean, check for how many.

85
00:06:04,720 --> 00:06:07,800
Real costs in this area.

86
00:06:08,820 --> 00:06:11,580
And we have a method for that.

87
00:06:11,580 --> 00:06:13,500
And we dive in more about three methods.

88
00:06:13,500 --> 00:06:15,420
For the meantime, let's solve this one.

89
00:06:15,510 --> 00:06:22,230
So we have, let's say, cons as to water to water record.

90
00:06:23,020 --> 00:06:24,210
Is equal to.

91
00:06:24,220 --> 00:06:27,900
I would take the books and on that half length.

92
00:06:28,930 --> 00:06:35,350
So if I console.log the the total record.

93
00:06:35,380 --> 00:06:39,370
Are we able to know I have four records in the array.

94
00:06:39,640 --> 00:06:42,230
One, two, three, four, go.

95
00:06:42,250 --> 00:06:49,240
So now if I add a record to it, let's say six and I save it, you see that I got five.

96
00:06:49,510 --> 00:06:56,890
So we are going to use this technique here inside our for loop so that it can be dynamic.

97
00:06:57,070 --> 00:07:02,140
So now coming back here, let me remove this one and now let me uncomment this one.

98
00:07:02,260 --> 00:07:06,370
So here is going to be the total record here.

99
00:07:06,730 --> 00:07:07,710
Like this one.

100
00:07:07,720 --> 00:07:11,120
So if I save it, you see that I get all the record.

101
00:07:11,140 --> 00:07:20,380
So in future, if I add in the record, whatever, let's say what books I add into it, let's say I

102
00:07:20,380 --> 00:07:23,800
want to add Angular.

103
00:07:24,760 --> 00:07:27,790
Now I get Angular being displayed.

104
00:07:27,790 --> 00:07:29,530
So this is more dynamic.

105
00:07:29,890 --> 00:07:37,510
So but by convention, we normally write everything in line than this one as a variable.

106
00:07:37,540 --> 00:07:43,360
Get a lamp and a reference ID here so we can quickly do it in line as books dot length.

107
00:07:43,720 --> 00:07:44,750
Yes, it is shorter.

108
00:07:44,770 --> 00:07:46,600
It is easier like that.

109
00:07:46,600 --> 00:07:52,060
So it is how we are able to look through an array and get a record in it.

110
00:07:52,210 --> 00:08:01,240
The next video we will talk about some of the array methods and then after that we will start with our

111
00:08:01,240 --> 00:08:02,860
coding challenge.

