Skip to content

Instantly share code, notes, and snippets.

@jkusachi
Created March 31, 2016 21:48
Show Gist options
  • Save jkusachi/f5b4a9489c0c381885dabe533ebf7a2a to your computer and use it in GitHub Desktop.
Save jkusachi/f5b4a9489c0c381885dabe533ebf7a2a to your computer and use it in GitHub Desktop.
Playing with Destructuring
var master = {
data: {
values: [1, 2, 3],
labels: ["one", "two", "three"],
food: {
name: "pizza"
},
groups: [
{
brand: 'zillow',
color: 'blue'
},
{
brand: 'ds'
},
{
brand: 'streeteasy',
city: 'new york'
}
]
}
}
var {data, data:{values, labels, food, food:{name}, groups:[zillow, ...otherGroups], groups:[,,{streeteasy}] }} = master;
console.log(values); // [1,2,3]
console.log(labels); //["one", "two", "three"]
console.log(food); //{ name: 'pizza'}
console.log(name); //pizza
console.log(zillow); //{brand: 'zillow', color: 'blue'}
console.log(otherGroups); //[{brand: 'ds'}, {brand: 'streeteasy', city: 'new york'}]
console.log(streeteasy); //streeteasy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment