Welcome back.
Today, we're going to discuss about iOS nine and what is the most important feature of this.
So there are more features, but this is the in this version in iOS nine or 2018, the most important
feature is object spread operator.
OK, create any file that you want.
So here I'm going to create an object cast in this object, by the way, it will hold the name of the
car and the amount of cars we have in stock, for example, Tesla.
And Tesla will have 40, then I will have Ram, Ram will have 15 and they will have four with 45.
Cool.
Now what I can do here, the sprint operator in year six was available for the.
But we can use it here on the object.
So I'm going to create consed here.
Curly brackets, BMW, the first one, the first item from the cars and I can use comma here three dots
and I can say a rest and that will be stored in the cars.
Nice.
So how is this is working.
Now if I copy this part here and if I go back to the console and if I sit down and enter nothing will
happen.
But let's now access the BMW.
Here it is.
The BMW have 50 cars in stock in.
What about the rest?
The rest will return as an object with the rest of the items from that car's object.
So how cool is this?
Right.
This is very nice.
And and we can use it now before as I say, as I said, that we can use it for an array.
For example, let array here and I will create an array with four items.
One sorry, instead of one, I'm typing two, one, two, three, four and five.
Right.
And let's create a function that will create that will calculate the average of this array.
So function eight KBG array and that function actually will have a will have how many parameters.
So we have five parameters here.
Amy C, d, e right now here.
I'm just going to return.
Return the A plus B plus C plus the plus E, and after that I'm going to see Ouray the length because
I want to grab the length and I want to divide the sum of this array here of these parameters.
Nice.
So we can call this EVGA.
All right here with dot, dot, dot array.
Right.
So we can use the spread operator over there.
Let's call it here.
Let's see what's happening.
I'm going to refresh here the browser.
I'm going to piece this one here.
I'm going to do it like that.
And the result, the output will be three.
Right, because this will give us 15 divided by five, and that is actually three.
So that is how we use this feature in a rate of forty eight.
Now that is pretty much it.
But I will, I will create one more function here and I will use the same logic for this one.
But I'm going to create a function to calculate the actual not look like I'm going to print out this
one.
So do use the again the object spread operator.
So I'm going to see object.
The name of the function will be object spread and it will take name one and name two.
So name one is actually going to be the name of any of this that you want.
So objects Fred.
Next in here, what I can do, I can print on the log a name one.
Right.
And cancel that log.
The need to know, OK, we have done this so only we need to call this outside.
So we need to call this function and we can pass the BMW right in the second parameter.
He's we can call it the rest.
Let's save it, and what we need to do right now is I need to comment at this point here, actually
this part here, and I want to copy the entire thing because I want to use the object again because
I refreshed it's nothing.
It's not there in the console lot.
So I'm just going to hit enter.
And here it is.
I do have the 15 and I do have the object of desire for RAM and Tesla.
Right.
So that is how we can use the spread operator over objects.
Right.
This super cool.
Super interesting.
And I hope you enjoyed this lecture because now you know how to use the spread operator over objects,
and that is super cool.
So I will see you in the next lecture.
Enjoy.