WEBVTT 00:06.440 --> 00:12.290 In this video you're going to learn how to use the optional map function when creating an array out 00:12.290 --> 00:13.440 of another object. 00:13.460 --> 00:18.590 Then you gotta learn how to create an array from any object with a length property. 00:18.620 --> 00:23.300 And finally you create arrays from each row with objects like sets and maps. 00:23.300 --> 00:25.490 So let's start with the map function. 00:25.700 --> 00:30.750 So let's create a string 00:45.540 --> 00:48.690 and let's create an array of this string 00:57.330 --> 01:02.770 so using the from method of the Array objects. 01:03.120 --> 01:06.060 And here is our array. 01:06.280 --> 01:06.500 All right. 01:06.510 --> 01:12.390 So now there is an optional function that you can pass to the frog method and that's called the map 01:12.420 --> 01:13.970 function. 01:14.100 --> 01:25.250 So this function is very similar to what you pass to the map method which you apply to arrays All right. 01:25.630 --> 01:31.360 And you just apply it to the elements of the array before creating it. 01:32.290 --> 01:44.400 So let's say that this method will take an Element X and will return x plus 01:48.890 --> 01:50.410 coma for example. 01:50.410 --> 01:52.150 All right. 01:52.520 --> 01:58.200 And you'll see that she applied that function to all the elements of the array. 01:58.430 --> 01:59.660 Right. 01:59.910 --> 02:09.670 So this was the map function is you can also use the map or the optional map function instead of the 02:09.730 --> 02:11.420 map function itself. 02:11.470 --> 02:11.890 So 02:14.800 --> 02:18.930 although using the map straight away is better but you can still do this. 02:19.150 --> 02:20.680 This is still correct. 02:21.340 --> 02:23.440 So you can apply that to the right 02:28.450 --> 02:32.350 so we're not converging here another type to the right. 02:32.380 --> 02:37.900 We just take an array and we using the mob function straight away like that. 02:38.000 --> 02:43.330 This is absolutely correct but it's better to use them of function straight away. 02:43.720 --> 02:44.720 All right. 02:45.340 --> 02:55.010 Now let's see how you can create arrays from any object with a length property. 02:56.050 --> 03:04.670 So we know that's a collection for example has got a limited property. 03:04.670 --> 03:10.580 So if you try to log collection that length 03:16.320 --> 03:17.670 you get the property that 03:21.110 --> 03:30.500 now you can create an array from any objects with a land property so an object like 03:36.950 --> 03:37.370 this one 03:41.110 --> 03:48.700 has got a limited property although it's not similar to an array or a collection but it's got a land 03:48.700 --> 03:54.790 property and consequently you can actually create an array out of it. 03:54.790 --> 04:02.990 So if you do a red dot from this object this is gonna create an array. 04:03.010 --> 04:04.710 So it's my nose. 04:05.080 --> 04:07.860 So you're getting an array of three elements. 04:07.870 --> 04:09.660 They all they're all in the point. 04:09.760 --> 04:21.610 Now if you use the optional map function so id say that this function will take a value inside the array 04:22.060 --> 04:25.800 and will return one for example. 04:26.170 --> 04:31.910 Then all these undefined are going gonna become one because you are returning one. 04:31.920 --> 04:40.990 So let's try and here Go Now the map function can take a couple of promises. 04:41.110 --> 04:44.470 So the first one is 04:48.100 --> 04:51.350 compulsory while the second one is optional. 04:51.670 --> 04:52.150 So 04:55.600 --> 05:00.930 the second one is gonna refer to the index of the elements inside the area. 05:01.030 --> 05:07.240 So let's say that instead of one you just returning index multiplied by two. 05:07.270 --> 05:11.940 So this time you get 0 2 and 4 the first index is 0 multiplied by 2. 05:11.980 --> 05:15.650 You get that index 1 multiplied by 2 you get that. 05:15.760 --> 05:18.040 And so on. 05:18.040 --> 05:18.340 All right. 05:18.340 --> 05:26.560 So now let's move to more sets and maps so you can create arrays from sets of maps as well. 05:26.560 --> 05:28.140 These are each where Will objects. 05:28.180 --> 05:30.500 And they also have a length property. 05:30.940 --> 05:37.140 So let's create a set using set structure. 05:37.570 --> 05:45.710 So let's are the few elements to our set. 05:45.910 --> 05:56.730 So if you remember inside a set you've got a collection of unique values. 05:57.870 --> 06:05.150 So if you log the set and see that you've got out a set of two elements let's check. 06:05.160 --> 06:08.240 But it's got a length property. 06:08.820 --> 06:15.120 So if you try not length it's not gonna work it's gonna give you undefined because we know that we need 06:15.120 --> 06:18.360 to use size instead of length for a set. 06:19.190 --> 06:21.480 Okay. 06:22.130 --> 06:28.880 So now we can create an array out of the set using array dots from 06:31.840 --> 06:35.210 and here we go. 06:37.490 --> 06:40.190 So now you've got an array of two elements. 06:40.190 --> 06:42.150 So the same thing applies to maps. 06:42.170 --> 06:45.560 So if you create a map 06:51.220 --> 06:54.310 using the map constructor so it's make things easy. 06:54.310 --> 07:01.380 I'm going to use an array which I'm going to post to the map with the key value pairs. 07:01.410 --> 07:12.070 So let's have a pair one and two add another one three and four so if you lock them up 07:16.210 --> 07:24.220 this is where you're gonna get and to create the right after the map you do that the same way you did 07:24.220 --> 07:26.470 with the set. 07:26.570 --> 07:27.490 Oh here we go. 07:27.490 --> 07:38.020 So you've got a couple of elements inside the array and each element is actually an array including 07:38.020 --> 07:42.460 the part of the key and the value prefix. 07:42.910 --> 07:50.290 So hopefully this gave you a really good understanding of how to create arrays from other data types 07:50.710 --> 07:54.700 or other collections in Essex. 07:54.850 --> 07:59.530 So in the next video you're going to have a look at another method of the array objects. 07:59.530 --> 08:00.790 It's the off method.