re: Alternative to the spread operator VIEW POST


good idea :)
if we want to keep the old value of pizza, how we do?


If you just want the original value of pizza you just put the object to the right so in

Object.assign(moreFood, food)

and with the spread operator you can

{...moreFood, food}

const newFood = Object.assign({}, food, moreFood)

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


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


const newFood = { ...food, ...moreFood };
code of conduct - report abuse