Issue
I have following Object
let car = { year: 2004, type: {name: "BMW"} }
Now i want to add a property to inner object "type". I want to to this with the spread operator, since i need a new object, because the existing is an immuteable state object. The result should be:
{ year: 2004, type: {name: "BMW", modell: "3er"}}
How can i do this?
Solution
const car = { year: 2004, type: {name: "BMW"} };
const modifiedCar = {...car, type: {...car.type, modell: "3er"}};
Answered By - chelmertz
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.