WEBVTT

00:00.780 --> 00:07.470
Yes, Sixel also to an object using the structuring, it gives us ability to get access and array items

00:07.800 --> 00:11.120
and also on properties of objects in kind of convenient and short wait.

00:12.080 --> 00:13.490
Let's see what I'm talking about.

00:14.110 --> 00:17.090
Let's say we have an array which consists of some numbers.

00:18.350 --> 00:26.360
For example, 10, 20, 30, 40, 50 and 60.

00:27.900 --> 00:33.870
And we want to get access on its items that you already know, that in iOS five we have the following

00:33.870 --> 00:34.220
way.

00:34.560 --> 00:37.320
Let's create variable 10.

00:39.370 --> 00:47.410
And then assigned to it array with index number zero, then create another variable.

00:48.530 --> 00:49.070
20.

00:50.430 --> 00:54.600
And assigned to it a right with index number one.

00:57.350 --> 01:04.310
So this is the way how we can access on everyday items in year five, but in Essex, thanks to the restructuring,

01:04.310 --> 01:06.130
we can do the same in a much shorter way.

01:06.830 --> 01:09.440
Let's call those lights out then.

01:09.440 --> 01:10.370
Right, concent.

01:12.710 --> 01:17.090
Open square brackets and put here the names of the variables 10.

01:18.120 --> 01:19.140
And 20.

01:21.970 --> 01:25.540
And after that, we need to link those variables to a rate.

01:28.270 --> 01:34.390
So if we lock those variables in council right here, 10 and 20.

01:39.380 --> 01:47.440
Then we will get 10 and 20 first and second items in council, so using the structuring, we have created

01:47.450 --> 01:51.960
variables and at the same time we have extracted items from an array.

01:52.610 --> 01:55.970
So as you see, we didn't need to declare separately variables.

01:56.300 --> 01:58.520
We just needed the one constant variable declaration.

01:58.790 --> 02:00.850
And also we have used array only once.

02:01.340 --> 02:07.190
As a result, we got items from array in order if we're right here, for example, 30.

02:09.620 --> 02:11.360
And also run it in council.

02:14.250 --> 02:16.560
Then we will get third item of our eight.

02:18.000 --> 02:23.130
All right, let's assume that we want to get access on sixth item, which is sixty.

02:23.670 --> 02:26.470
For that, we need to miss two items, 40 and 50.

02:26.970 --> 02:32.250
And in order to achieve that, we just need to place you to commerce and then.

02:32.250 --> 02:34.110
Right, for example, 60.

02:35.340 --> 02:37.590
Let's run it in council.

02:41.810 --> 02:44.930
And you see that we got last item of our 860.

02:45.910 --> 02:51.700
All right, we're able to use rest parameter when we deal with restructuring, so in order to get the

02:51.700 --> 02:57.130
rest of the items, let's insert here dot, dot, dot items.

02:59.210 --> 03:01.310
Then also run it in council.

03:04.950 --> 03:12.680
Revolt, and we have 10, 20 and the rest of the items, but as you see, they are represented in the

03:12.710 --> 03:12.910
right.

03:13.230 --> 03:16.180
That's because, as we know, the parameter returns an array.

03:16.530 --> 03:21.600
So in order to get them like first and second items, I mean, to get them in normal, we were able

03:21.600 --> 03:23.000
to use separate operator.

03:23.670 --> 03:30.720
So it would place you three dots before items that it will take out array items and display them in

03:30.720 --> 03:31.170
Castle.

03:34.140 --> 03:34.590
All right.

03:35.950 --> 03:41.950
This is the way how we can use this structuring with a race and I'm going to talk about objects at first,

03:41.950 --> 03:49.840
let's create an object, call it person, then insert here some properties.

03:49.840 --> 03:50.470
First name.

03:51.910 --> 03:56.860
John, then last name, Smith.

03:58.580 --> 04:06.650
And age 30, as you remember, in year five, we used to access on properties of objects using the following

04:06.650 --> 04:06.930
weight.

04:07.700 --> 04:12.740
You know, sometimes we write these five code, but I'm trying always to use constant, loud declarations

04:13.190 --> 04:15.270
because I want you to quickly adapt with them.

04:15.710 --> 04:21.290
So in order to get access on first name and last name properties and store them in variables, we have

04:21.290 --> 04:26.090
to write consent a equals to person dot first name.

04:28.480 --> 04:33.310
That constantly equals to person dot last name.

04:36.370 --> 04:41.810
So this is the way of life, but in Essex, we can restructure objects as well.

04:42.160 --> 04:45.940
Let's comment this code out and then create constant.

04:48.160 --> 04:54.700
In case of objects, we need to use color braces and then right first name.

04:57.490 --> 04:58.180
Last name.

05:00.070 --> 05:03.520
And also like those variables to person object.

05:06.270 --> 05:09.870
Let's round them in council, right, first name.

05:11.740 --> 05:12.850
And last name.

05:15.910 --> 05:24.850
Reload, so we have here John Smith, OK, you may wonder if those names of variables have to be matched

05:24.850 --> 05:31.390
with names of properties and the answer is yes, if we change, for example, last time it is surname.

05:33.260 --> 05:35.060
And also rotating council.

05:38.790 --> 05:40.170
Then we will get undefined.

05:41.140 --> 05:47.290
Actually, it means that JavaScript engine couldn't find relevant value for certain variable in person

05:47.290 --> 05:47.770
object.

05:48.860 --> 05:52.220
In case of objects, we don't have to protect order of properties.

05:52.640 --> 05:56.490
It doesn't matter if we write it first or last name.

05:56.840 --> 06:00.080
The key point is to match names of variables to properties.

06:00.620 --> 06:08.300
So if we're right h at the beginning and then change back surname into a last name.

06:11.450 --> 06:12.920
Also them in council.

06:16.260 --> 06:19.320
We will get 30 and John Smith.

06:20.760 --> 06:25.800
All right, let's go ahead and describe how we can use the structuring of objects with functions.

06:26.200 --> 06:33.040
Let's comment this code out and create function expression, let's call it about me.

06:34.590 --> 06:39.540
I'm going to insert here parameter John, which actually will represent person object.

06:42.220 --> 06:51.880
And then I'm going to restructure person object, so write consent that open the braces and write the

06:51.880 --> 07:01.750
first name, last name and age and also link those variables to parameter John.

07:04.100 --> 07:12.920
Let's run in council, right, counsel, like I am, then insert your variable first name.

07:15.740 --> 07:17.570
That last name.

07:21.190 --> 07:22.990
Then write the text and I am.

07:24.640 --> 07:29.640
Also place here, the age variable and then years old.

07:32.650 --> 07:37.390
Let's call this function and as an argument use person object.

07:40.420 --> 07:45.460
Reload and we have I am John Smith, and I'm 30 years old.

07:47.220 --> 07:48.820
All right, it's fine.

07:48.820 --> 07:51.730
But we can write this stuff in much concise way.

07:52.180 --> 07:58.060
We can directly this structure person object and incertain as a parameter instead of John.

07:59.780 --> 08:01.480
Also, we don't need this line.

08:03.190 --> 08:04.630
So let's reload.

08:05.500 --> 08:07.570
And you see that we have the same result.

08:08.530 --> 08:11.140
But as I see in more concise way.

08:12.160 --> 08:13.780
All right, that's it.

08:14.110 --> 08:19.040
So in this lecture, we have learned what the structuring is and how to use it with Arason objects.

08:19.360 --> 08:20.560
See you in the next video.
