Learn JavaScript
Copying Objects
37.9
Lesson

Overwrite Reassigned Property

We can use the Object.assign method to add any property while cloning an object. If the property name already exists, it gets overwritten.

In the example given below, the value of the age property in the user object gets overwritten to 45.