July 2017
Intermediate to advanced
300 pages
5h 43m
English
In new JavaScript, we can extract specific data from arrays and objects. Let's say, we have an array that could be built by an external function, and we want its first and second elements. We can extract them as simple as this:
const robots = [ "R2D2", "C3PO", "BB8" ]; const [ r2d2, c3po ] = robots; console.log( r2d2, c3po );
So here, we declare two new constants--r2d2 and c3po--and assign the first and the second array elements to them, respectively.
We can do the same with objects:
const meta = { occupation: "Astromech droid", homeworld: "Naboo" }; const { occupation, homeworld } = meta; console.log( occupation, homeworld );
What did we do? We declared two constants--occupation and homeworld--that receive values from ...
Read now
Unlock full access