1
00:00:00,920 --> 00:00:04,400
This video is about accessing.

2
00:00:05,280 --> 00:00:06,870
I raised goat.

3
00:00:06,880 --> 00:00:10,380
So let me comment out this.

4
00:00:11,730 --> 00:00:12,600
Like that.

5
00:00:12,600 --> 00:00:15,240
And now let's calm down here.

6
00:00:17,150 --> 00:00:19,370
As accessing.

7
00:00:20,470 --> 00:00:21,430
I read.

8
00:00:22,630 --> 00:00:25,250
Okay, so let's declare a variable cost.

9
00:00:25,270 --> 00:00:28,990
Let's say books array is equal to.

10
00:00:29,020 --> 00:00:35,440
Now we are going to take the easiest way that is using the square brackets without using the new.

11
00:00:35,470 --> 00:00:38,010
I mean, the new syntax or the new keyword.

12
00:00:38,020 --> 00:00:39,740
So this is the easy way to go.

13
00:00:39,760 --> 00:00:44,230
So let's say that I want to save MongoDB into this.

14
00:00:45,040 --> 00:00:53,080
After that, Node.js is not period, but instead is comma comma separated.

15
00:00:53,290 --> 00:00:58,810
The next one is I also want to save React JS into it.

16
00:00:58,990 --> 00:01:00,880
So this is my book what?

17
00:01:00,910 --> 00:01:02,290
My book array.

18
00:01:02,320 --> 00:01:09,220
Now if I check my books here we see that I have the red code inside this.

19
00:01:09,520 --> 00:01:14,320
And as before, how can we access array?

20
00:01:14,860 --> 00:01:19,000
Well, we have two ways of accessing arrays.

21
00:01:19,030 --> 00:01:21,910
That is using the.

22
00:01:22,900 --> 00:01:26,050
Index of heart rate.

23
00:01:26,140 --> 00:01:29,500
And that is what I have explained before over here.

24
00:01:29,770 --> 00:01:37,510
So for this one, if we want to access, let's say, this book, you refer by eight index.

25
00:01:37,510 --> 00:01:43,540
So let's come down here, let's say get first book.

26
00:01:45,070 --> 00:01:45,940
First.

27
00:01:47,110 --> 00:01:47,730
Book.

28
00:01:47,740 --> 00:01:48,760
So here you go.

29
00:01:48,940 --> 00:01:49,870
So.

30
00:01:50,690 --> 00:01:55,190
Books and then my square bracket and then zero.

31
00:01:55,280 --> 00:01:56,600
That's my first book.

32
00:01:56,720 --> 00:02:05,720
Okay, so I can assign this one to, let's say cost, let's say book one as B one, book one.

33
00:02:05,720 --> 00:02:10,610
So if I console that log book one, that is my B one.

34
00:02:10,610 --> 00:02:13,130
I have MongoDB here.

35
00:02:13,550 --> 00:02:18,620
So if I want access, second book, third book and the fourth book.

36
00:02:18,620 --> 00:02:22,050
So let's access second book.

37
00:02:22,070 --> 00:02:31,640
So the second book is going to be B two here and now second book will be at index one because the zero

38
00:02:31,640 --> 00:02:32,240
base.

39
00:02:32,420 --> 00:02:35,300
So if I check for book two here.

40
00:02:36,190 --> 00:02:37,090
Like that.

41
00:02:37,180 --> 00:02:40,150
So can you access book three?

42
00:02:40,360 --> 00:02:44,380
Well, you can put this video and then try your luck on that.

43
00:02:44,560 --> 00:02:49,770
So book three, I can copy this one and say this is my book three.

44
00:02:49,780 --> 00:02:54,430
I want access at index two and then book four.

45
00:02:55,840 --> 00:02:57,250
Here are going to be three.

46
00:02:58,180 --> 00:02:59,980
And then here are going to be.

47
00:03:01,310 --> 00:03:02,020
Four.

48
00:03:02,060 --> 00:03:06,500
So here is going to be B to B three and then B four.

49
00:03:06,860 --> 00:03:11,240
So if I search for B.

50
00:03:11,920 --> 00:03:12,780
Two.

51
00:03:12,820 --> 00:03:13,930
I have no jazz.

52
00:03:13,960 --> 00:03:17,130
If I search for B three, I have react.

53
00:03:17,140 --> 00:03:22,030
If I access B four, I have no jazz.

54
00:03:22,120 --> 00:03:27,850
What about if I'm trying to access a data that is inside my array?

55
00:03:27,880 --> 00:03:29,680
What is going to return?

56
00:03:30,040 --> 00:03:34,170
So let's say that I want access for this one before you're going to be with three.

57
00:03:34,180 --> 00:03:34,930
Sorry, guys.

58
00:03:35,110 --> 00:03:38,440
Let's say I want to access index seven here.

59
00:03:39,140 --> 00:03:42,060
Do we have index screen here inside this one node?

60
00:03:42,080 --> 00:03:49,570
So if I console that, log the book for let's see the book four, we see that I get undefined.

61
00:03:49,580 --> 00:03:59,540
So it means that if a record that you are trying to access is not inside, the array is going to retain

62
00:03:59,540 --> 00:04:01,040
undefined.

63
00:04:01,550 --> 00:04:02,750
All right, the next video.

64
00:04:02,750 --> 00:04:07,160
Let's see how we can attract over an array.

