Sometimes objects have properties that are references to other objects. In such cases, it is not enough to clone the object by iterating over all its properties.
In the example given below,
the same property
Here, changing the
also changes it in the
This is because the
status properties of
user are references to other objects.
We can use the
to clone an object that has nested objects as its properties.
In the example given above,
JSON.stringify method converts the
user object into a JSON string.
JSON.parse method converts the JSON string back into an object.
When we make changes in the
firstName property using
the changes are not visible in the