updating a key value on javascript object es6 1

updating a key value on javascript object es6

var obj = {id: 1, name: "Adam"}
console.log(obj) // {id: 1, name: "Adam"}
obj = {...obj, name: "Eve"}
console.log(obj) // {id: 1, name: "Eve"}

Here is what the above code is Doing:
1. We create an object with two properties: id and name.
2. We log the object to the console.
3. We create a new object with the same id property, but a different name property.
4. We log the new object to the console.

Similar Posts