Created
October 27, 2016 03:46
-
-
Save wklug/6acf63053f458dd62136fa88c747c69b to your computer and use it in GitHub Desktop.
ES6 - Destructuring assignment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* ES6 - Destructuring assignment | |
**/ | |
var [person1, person2, person3, ...otherPeople] = [ | |
{ | |
name: 'P. Nutt', | |
age: 18 | |
}, | |
{ | |
name: 'Hazel Nutt', | |
age: 28 | |
}, | |
{ | |
name: 'Manny Bones', | |
age: 88 | |
}, | |
{ | |
name: 'John Doe', | |
age: 25 | |
}, | |
{ | |
name: 'Jane Doe', | |
age: 24 | |
} | |
]; | |
console.log(`${person1.name} is ${person1.age} years old`); // P. Nutt is 18 years old | |
console.log(`${person2.name} is ${person2.age} years old`); // Hazel Nutt is 28 years old | |
console.log(`${person3.name} is ${person3.age} years old`); // Manny Bones is 88 years old | |
otherPeople.map((person) => { console.log(`${person.name} is ${person.age} years old`) }); // John Doe is 25 years old, Jane Doe is 24 years old |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment