There are three types of syntax using which we can copy objects in javascript.
const area = {
let length = 5,
let breadth = 5,
let type = 'square',
};
//Shallow copy
- Using spread operator:
let sqr= {
...area
};
//Shallow copy
- Using object method:
let sqr = Object.assign({}, area);
//Deep copy
- Using JSON method:
let sqr = JSON.parse(JSON.stringify(area));
Top comments (1)
Great one, thanks for sharing.