Skip to content

Instantly share code, notes, and snippets.

@eljamez
Last active December 10, 2017 22:43
Show Gist options
  • Save eljamez/d0dcb0e97e41d7f2c04d1af2bd188706 to your computer and use it in GitHub Desktop.
Save eljamez/d0dcb0e97e41d7f2c04d1af2bd188706 to your computer and use it in GitHub Desktop.
es6 spread and concat, add to array of objects.
const myObj = {
list: [
{name: 'bill'},
{name: 'fred'}.
],
};
const newObj = {
...myObj,
list: myObj.list.concat({name: 'sam'})
};
console.log('---- returns bill and fred ----');
console.log(myObj.list);
console.log('---- returns bill, fred, and sam ----');
console.log(newObj.list);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment