Let's get started with the structuring based on my own definition.
I regard this structuring as a way of unpacking a box or a container.
When you unpack a box or a container, it means that you are taking what you want out from the box.
So in short, disruption is a way to extract data from arrays and objects.
So let's see with real code.
So back to visuals to the code.
I have already created a folder called is six and inside I have two files my a html and my JavaScript
file.
So inside my HTML, I have connected my JavaScript file as that.
So now let's make our hands dirty with its features.
And the first one you talk about is called the structuring.
In this particular video.
Let's get started with a rain destruction.
De structuring.
Let's say this is our array with these values.
One, two, three, four and five.
So.
Let's say that we want to retrieve the first value.
That is one we can use the index of to retrieve that.
What we need to do is I'll bring in my variable mine square bracket and add the first index and I think
it will give me one.
Okay, so let's prove it inside the console.
So back to my console here.
Let's open it.
Now, let's try to retrieve the first index zero and then mine is that I get one.
If I want the second value and change this 1 to 1, I'll get a second value, which is two.
The same thing applies to two.
I will get the value of three inside here.
There is nothing new until this point, but there is a better way of doing this than using the index
and a square bracket.
That is where the destruction comes into play.
So that's how are going to do so.
Let's say that I want to retrieve these values or what I need to do is bring mine cost and then my square
bracket is equal to the array.
Perfect.
So now for this one, because I have how many values I have one, two, three, four, five.
So I can represent anything which represents these values.
I can say it can be A, B, C and D with this one.
So if I want the first the first one, A represents one, B represent two and C and as that.
So in my console, if I make use of a C that I get one, if I make use of B, I get to see I get three,
D, I get four.
And then what about let me add one more in the mix.
Let's say E and then F.
Good.
So now let's retrieve I mean, E also E, which is five perfect.
And then what about F?
Well, undefined because it doesn't exist.
Because we have how many records we have.
One, two, three, four, five.
And now here we have how many destruction data here?
One, two, three, four, five, six.
So there is no value for this for this one.
The arrangement model a lot.
So the first one represent this first one.
Second one, we can use any name here.
We can make it as number one or here as number two or here as what?
Let's say number four.
And then in my three here and let's say this, I'm going to be as number four and then this one as number
five.
It is simple.
You can use any variable to represent the data in the array.
So the same thing, we can have arrays of objects and then we get back into that very soon.
So let's have some arrays of objects and let's see.
So let's say that I have this const and let's say users as that and inside my array I can add the first
object, I can say let me add my equal sign here and inside.
Let's say I have the name.
Let me say the user name.
Let's say it's Ben.
And then let's say the age of this particular user is, let's say 20.
I have my first user.
So let me.
Have some room here so I can copy this one and then paste it here.
And I have is to when I be as John.
And the age is 30.
Yes.
So for this one too, I can structure it easily.
So if I want the first user, I make use of users and then my square bracket and then the first in this
one to retrieve the first user.
So let's see it inside the console here.
Okay.
So now if I make this of users and then I get all the array if I want the first one square bracket zero
as that I get the first one with destruction.
Is going to make our life easier.
So I'll bring in const my array and then the original array.
So in here I can say I'm going to be as user one and let's say user two as that.
So inside my console, if I make use of user one, I get as before user two as that's that is about
how we can this structure array.
The next video you will see how we can do structure object.