Last active
December 10, 2017 22:43
-
-
Save eljamez/d0dcb0e97e41d7f2c04d1af2bd188706 to your computer and use it in GitHub Desktop.
es6 spread and concat, add to array of objects.
This file contains hidden or 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
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