So next, we're going to talk about a raid, restructuring and restructuring, all that means is to
unpack the array elements.
So what you can do is if you have an array and you assign it to another array like Array X, comma Y,
this is kind of an array of variables equals one, two, three, four, five.
It's going to assign the one to X and the two to Y in the three, four or five.
Just get the fall off the end.
You can skip one or more by saying, let X, comma, comma, Y equals one, two, three, four or five,
X is going at one, Y is going to get three and it's going to get two.
And then finally, there's what's called the rest operator, which looks a lot like the spread operator
because it's a dot, dot, dot.
But what it just means is put the rest here.
And so when I say let X. comma, dot, dot, dot more, it's going to put one into X an array of two,
three, four or five in the more.
And then finally, you can provide default values.
So in this case, I only have one element in the array.
So when I say X equals three more, it gets replaced by the one the Y gets for because that's the default.
So let's take a look at a few examples of this.
All right, so let's kind of walk through the example so the destruction requires variables, you can
declare them like I did on the slides when you use them or you can declare them separately.
So I can say let X, Y and we'll have a couple of variables.
And then I could say X, comma Y equals to come forward comma six come eight or it doesn't have to be
a literal it can be a variable itself, of course.
So let's make a variable what my array equals and then I can say my array and then console that log
and let me use the template format here, the string template and I say X equals.
Y equals.
All right.
So it's.
So access to an Ys for.
Which is fine if we continue out with this A, B, C, D and.
Just copy this with the camera, so say why A, B, C, D, so its search for the Y.
So we don't want to change this one, I'm hitting up three to go between, so this one's going to be
A, A, B, B, C, C, the D, and of course, we have to declare our variables, otherwise it wouldn't
work very well.
So we'll say, what A, but B, let's see
what.
And so why would a car like this are undefined.
All right, let's see what happens.
We've got two, four, six, eight, C is undefined and DS undefined because it wasn't in the original
thing, but if I said C equals three and D equals four, then then have a value because there's a default.
So these three ideas for in this case.
All right, so now let's just look at the more operator, the rest operator, I'm sorry.
So we want to do is to find an array.
First, to put the values in and then we will say XCOM DataDot, other Arae equals my array
and then let's copy this
and.
Will say.
All right, let's run that.
So this year, our original rate was two, four, six, eight.
So the X got the two and the other Ray got four, six, eight, six covers of Ray destruction.
We're going to be looking at this more later with objects as well as what, the spread operator.
So in the meantime, practice using this and it'll start to make sense to you after a while.