DEV Community

Discussion on: Alternative to the spread operator

Collapse
 
rhymes profile image
rhymes
const newFood = Object.assign({}, food, moreFood)

this will keep both intact and create a new object with the merged keys and values

Collapse
 
brianmcoates profile image
Brian

Love it thank you! Is there is there a way to do that with the spread operator as well?

Thread Thread
 
rhymes profile image
rhymes

Yes:

const newFood = { ...food, ...moreFood };