3.0 destruction
So we learned about resting the spread there is a feature that I want to cover the next generation that is called destructuring the destructuring allows you to easily extract array elements from the properties of objects and store them in variables when you hear about this for the first time it may seem like exactly what the propagation operator is doing
but it’s a different spread thing removes all elements from all properties and distributes them in a new array or object or any other place and destructuration allows you to extract unique property elements and store them in variables arrays and objects now for arrays it looks like this we have an array with two elements hello and Matthew so we can use this strange syntax on the left side of the equal sign that looks like an array creation but we don’t have to assigned with variables A and B to hello and Matthew respectively and for the same syntax with braces and or in an array the de-structuring the defined order.
what property we take for the destruction of the object is the name of the property so accolade named to accolade on the left side targets the property name of the object on the right side and extract the value reason why the age of the logging generates a result not defined we don’t remove this from the object here so it’s the break-up start with our array of numbers it has the numbers 1 2 3 and now we want to get the number 1 and 2 then we can use this array syntax to the left of the Equal Sign and choose the names of variables of our choice such as number 1 and number 2 and assign it an equal number to table if I now consume newspapers number 1 and number 2
now if I run it puts me 1 and 2 Imagine if I only want 1 and 3 we Change only the number here and if I have added a comma and If I run it puts me one and three it is a table of destruction now the destructuring of the objects and also taken in load by our project because it is used in this course however it is not supported by jsbin here so I can not show you unfortunately but I showed the syntax on the slide. This is the syntax where you use braces on the left and see the property that was with its name of two properties in this course I wouldn’t use too often this is destructuring syntax but I want to inform you of their existence and the fact that it constitutes a practical way to write some elements of the table where properties with their object values are found on the next course.