Yes, Sixel also to an object using the structuring, it gives us ability to get access and array items
and also on properties of objects in kind of convenient and short wait.
Let's see what I'm talking about.
Let's say we have an array which consists of some numbers.
For example, 10, 20, 30, 40, 50 and 60.
And we want to get access on its items that you already know, that in iOS five we have the following
way.
Let's create variable 10.
And then assigned to it array with index number zero, then create another variable.
20.
And assigned to it a right with index number one.
So this is the way how we can access on everyday items in year five, but in Essex, thanks to the restructuring,
we can do the same in a much shorter way.
Let's call those lights out then.
Right, concent.
Open square brackets and put here the names of the variables 10.
And 20.
And after that, we need to link those variables to a rate.
So if we lock those variables in council right here, 10 and 20.
Then we will get 10 and 20 first and second items in council, so using the structuring, we have created
variables and at the same time we have extracted items from an array.
So as you see, we didn't need to declare separately variables.
We just needed the one constant variable declaration.
And also we have used array only once.
As a result, we got items from array in order if we're right here, for example, 30.
And also run it in council.
Then we will get third item of our eight.
All right, let's assume that we want to get access on sixth item, which is sixty.
For that, we need to miss two items, 40 and 50.
And in order to achieve that, we just need to place you to commerce and then.
Right, for example, 60.
Let's run it in council.
And you see that we got last item of our 860.
All right, we're able to use rest parameter when we deal with restructuring, so in order to get the
rest of the items, let's insert here dot, dot, dot items.
Then also run it in council.
Revolt, and we have 10, 20 and the rest of the items, but as you see, they are represented in the
right.
That's because, as we know, the parameter returns an array.
So in order to get them like first and second items, I mean, to get them in normal, we were able
to use separate operator.
So it would place you three dots before items that it will take out array items and display them in
Castle.
All right.
This is the way how we can use this structuring with a race and I'm going to talk about objects at first,
let's create an object, call it person, then insert here some properties.
First name.
John, then last name, Smith.
And age 30, as you remember, in year five, we used to access on properties of objects using the following
weight.
You know, sometimes we write these five code, but I'm trying always to use constant, loud declarations
because I want you to quickly adapt with them.
So in order to get access on first name and last name properties and store them in variables, we have
to write consent a equals to person dot first name.
That constantly equals to person dot last name.
So this is the way of life, but in Essex, we can restructure objects as well.
Let's comment this code out and then create constant.
In case of objects, we need to use color braces and then right first name.
Last name.
And also like those variables to person object.
Let's round them in council, right, first name.
And last name.
Reload, so we have here John Smith, OK, you may wonder if those names of variables have to be matched
with names of properties and the answer is yes, if we change, for example, last time it is surname.
And also rotating council.
Then we will get undefined.
Actually, it means that JavaScript engine couldn't find relevant value for certain variable in person
object.
In case of objects, we don't have to protect order of properties.
It doesn't matter if we write it first or last name.
The key point is to match names of variables to properties.
So if we're right h at the beginning and then change back surname into a last name.
Also them in council.
We will get 30 and John Smith.
All right, let's go ahead and describe how we can use the structuring of objects with functions.
Let's comment this code out and create function expression, let's call it about me.
I'm going to insert here parameter John, which actually will represent person object.
And then I'm going to restructure person object, so write consent that open the braces and write the
first name, last name and age and also link those variables to parameter John.
Let's run in council, right, counsel, like I am, then insert your variable first name.
That last name.
Then write the text and I am.
Also place here, the age variable and then years old.
Let's call this function and as an argument use person object.
Reload and we have I am John Smith, and I'm 30 years old.
All right, it's fine.
But we can write this stuff in much concise way.
We can directly this structure person object and incertain as a parameter instead of John.
Also, we don't need this line.
So let's reload.
And you see that we have the same result.
But as I see in more concise way.
All right, that's it.
So in this lecture, we have learned what the structuring is and how to use it with Arason objects.
See you in the next video.