1
00:00:00,970 --> 00:00:06,580
I have a challenge for you in this lesson, it's to create an array that contains objects created dynamically

2
00:00:06,580 --> 00:00:10,270
using a loop, so output the content into the console.

3
00:00:10,280 --> 00:00:13,280
So it looks like the example on the right hand side.

4
00:00:13,570 --> 00:00:15,490
So create this using a loop.

5
00:00:15,760 --> 00:00:20,410
And we saw how we can create an array as well as how we can create objects.

6
00:00:20,590 --> 00:00:26,050
Also use the filter to create a new array only with the items that have the value of true.

7
00:00:26,650 --> 00:00:32,440
So first, we're setting up a value for my work and this is going to be an array.

8
00:00:33,670 --> 00:00:41,320
And then using a loop, we're going to start the loop at one and we're going to loop through while X

9
00:00:41,320 --> 00:00:45,430
is less than ten and then increment X by one.

10
00:00:46,270 --> 00:00:49,450
And we want to push a value into my work.

11
00:00:50,720 --> 00:00:55,490
So this isn't a race or using their race method, it will create a variable that's going to contain

12
00:00:55,490 --> 00:00:56,550
a value for temp.

13
00:00:57,050 --> 00:00:59,690
So for now, we'll just equal temp.

14
00:01:00,380 --> 00:01:03,290
So set up temp within this loop.

15
00:01:04,090 --> 00:01:11,800
And we're going to equal attempt to whatever the value of access for, let's console logout the contents

16
00:01:11,800 --> 00:01:12,670
of my work.

17
00:01:13,730 --> 00:01:20,180
So you can see that we constructed our array and it's got all of the different values, so starting

18
00:01:20,180 --> 00:01:26,960
at index zero, so one all the way to nine, let's extend on that and create an object.

19
00:01:27,680 --> 00:01:33,920
So we're checked to see if X modulus is equal to true or false.

20
00:01:33,950 --> 00:01:38,510
So depending on if it's odd or even we're going to have a different value for stat.

21
00:01:38,510 --> 00:01:44,420
And then as we're pushing as we're constructing temp, we're going to create temp into an object that's

22
00:01:44,420 --> 00:01:50,710
going to have a name and the name for this object, we can use a template literal for lesson.

23
00:01:50,750 --> 00:01:53,140
You can have concatenate it as well together.

24
00:01:53,150 --> 00:01:57,970
So there is a few options there and then status will just be equal to stop.

25
00:01:57,980 --> 00:02:04,690
So now we can see the contents of the array going to be all these objects can filter them, construct

26
00:02:04,690 --> 00:02:05,770
a brand new array.

27
00:02:05,780 --> 00:02:14,300
So taking our get the ones that are true, we're going to look through the my work array and use filter,

28
00:02:14,330 --> 00:02:15,710
which is going to create a new array.

29
00:02:15,860 --> 00:02:23,810
So just as we did before returning back, that element value and we're returning back the element with

30
00:02:23,810 --> 00:02:28,010
a status and because status is a boolean value.

31
00:02:28,010 --> 00:02:30,030
So it's only going to return back the true ones.

32
00:02:30,050 --> 00:02:37,880
So if we cancel, log out the get true array, you're going to see that we're only containing the objects

33
00:02:38,150 --> 00:02:42,650
that are true, that are available within the array that was constructed.
