Skip to content

Instantly share code, notes, and snippets.

@rafagarcia
Last active September 11, 2018 16:51
Show Gist options
  • Save rafagarcia/30539f465def48726eb346e476d3b249 to your computer and use it in GitHub Desktop.
Save rafagarcia/30539f465def48726eb346e476d3b249 to your computer and use it in GitHub Desktop.
JS Bin// source http://jsbin.com/savexuv
// Destructuring nested object
var car = {
model: 'bmw 2018',
engine: {
v6: true,
turbo: true,
vin: 12345
}
}
const modelAndVIN = ({model, engine: {vin}}) => {
console.log(`model: ${model} vin: ${vin}`);
}
modelAndVIN(car);
// merge objects
let object1 = { a:1, b:2, c:3 }
let object2 = { b:30, c:40, d:50}
let merged = {...object1, ...object2} //spread and re-add into merged
console.log(merged); // {a:1, b:30, c:40, d:50}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment