Creating Deep Copies of Objects in Javascript


Use JSON.parse and JSON.stringify to create a deep copy of an object.

Source Code

let original = { name: 'John', address: { city: 'New York' } };
let copy = JSON.parse(JSON.stringify(original));
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments