1
00:00:01,580 --> 00:00:02,540
In this video.

2
00:00:02,540 --> 00:00:10,070
Let's switch from the waste we are or ways we can attract over objects and talk about one important

3
00:00:10,070 --> 00:00:13,850
loop in JavaScript code for mean for each loop.

4
00:00:14,360 --> 00:00:19,580
This method was introduced in the E6, a new feature in JavaScript.

5
00:00:19,640 --> 00:00:27,830
So for each loop is used to upgrade over arrays or the array of objects or this array on its own.

6
00:00:28,070 --> 00:00:31,100
So let's say that we have const.

7
00:00:31,100 --> 00:00:33,230
Let's see, const.

8
00:00:34,070 --> 00:00:36,060
Let's say I have my records.

9
00:00:36,080 --> 00:00:41,030
Let's say I have one for six, this and that.

10
00:00:41,030 --> 00:00:44,060
And I want to display this data individually.

11
00:00:44,060 --> 00:00:46,580
I'm going to use the for each loop.

12
00:00:46,700 --> 00:00:50,840
So it's how it works on the it works on array, right?

13
00:00:50,840 --> 00:00:54,650
So let's say this my array, which is this one.

14
00:00:54,650 --> 00:01:00,890
And then on that I will have for each, then as a function, then I'll pass in my callback function

15
00:01:00,890 --> 00:01:05,090
as this remember because we have discussed this one before.

16
00:01:05,600 --> 00:01:10,250
So a function that is passed into another function is what you call callback.

17
00:01:10,370 --> 00:01:13,730
So inside here I have access to my individual record.

18
00:01:13,730 --> 00:01:18,200
Let me see as data here can be any variable anything.

19
00:01:18,770 --> 00:01:21,590
So this one represent an individual record in my array.

20
00:01:21,590 --> 00:01:30,020
So if I console.log the data in my callback instead, I have one, two, three here.

21
00:01:30,200 --> 00:01:40,150
So the same way, if we want to get an individual record for our object keys, we can use the for each

22
00:01:40,160 --> 00:01:40,550
loop.

23
00:01:41,290 --> 00:01:42,860
So let's see.

24
00:01:42,880 --> 00:01:49,480
Let me now use the my keys here that I got after I tripped over my object called person object.

25
00:01:49,480 --> 00:01:50,770
So now here we go.

26
00:01:51,010 --> 00:01:56,920
If I change this one to my keys instead of erase when I save it, let's see.

27
00:01:57,370 --> 00:02:00,160
Now I get it as before.

28
00:02:00,610 --> 00:02:04,600
So this method, a key object keys.

29
00:02:04,630 --> 00:02:06,970
Give us the array of record.

30
00:02:08,120 --> 00:02:16,190
The keys and put them in an array and then four, four, four in loop it just give me the properties

31
00:02:16,190 --> 00:02:17,900
or the keys on the fly.

32
00:02:18,590 --> 00:02:25,670
So if I uncomment this one out and let me also comment this one out here, let me save it.

33
00:02:25,700 --> 00:02:29,420
You see that this is for a loop method, which is which is here.

34
00:02:30,140 --> 00:02:37,850
But for the the keys, it doesn't give us this if we want to achieve this way using the the keys, unless

35
00:02:37,850 --> 00:02:45,380
you go another level by converting to array and then use for each method and then loop through.

36
00:02:45,410 --> 00:02:49,400
So the same way for this line of code here, let me comment this one.

37
00:02:49,640 --> 00:02:52,340
Let me bring back my for each.

38
00:02:52,340 --> 00:02:57,080
So here, first of all, I converted my keys to array.

39
00:02:57,780 --> 00:03:00,480
So let me console.log before my kick.

40
00:03:00,480 --> 00:03:03,180
Here, let me console that.

41
00:03:03,180 --> 00:03:03,630
Look it.

42
00:03:03,630 --> 00:03:05,160
Here, let me show you here.

43
00:03:05,610 --> 00:03:11,130
Now, this is the one because it's one for demonstration to show you why how the for each loop works.

44
00:03:11,460 --> 00:03:15,120
So if I console.log, it is that I have this one.

45
00:03:15,120 --> 00:03:15,660
No, no, no.

46
00:03:15,660 --> 00:03:16,620
I don't want this one.

47
00:03:16,770 --> 00:03:19,410
I have the properties in an array.

48
00:03:19,710 --> 00:03:23,850
So if I want to get the same result as this one, this for a loop.

49
00:03:23,850 --> 00:03:33,540
Unless I go another level by converting using the map for h, then I can get the same as that.

50
00:03:33,570 --> 00:03:39,780
That is about the for I mean the keys and then the for each loop for you.

51
00:03:40,080 --> 00:03:41,130
The next video.

52
00:03:41,130 --> 00:03:42,870
Let's talk about this.

53
00:03:42,900 --> 00:03:44,070
Let me see what we have.

54
00:03:44,100 --> 00:03:46,740
I mean, object values.

55
00:03:46,740 --> 00:03:48,810
The name is even clear here.

56
00:03:48,810 --> 00:03:51,780
So let me show you what you're going to do in this video.

