Shallow Copy | Deep Copy |
---|---|
Original and shallow copy both point to the same memory location | Original and deep copy point to different memory locations |
Use ... spread operator: let shallowCopy = {...original} |
Use JSON : let deepCopy = JSON.parse(JSON.stringify(original)) |
Use Object.assign() : let shallowCopy = Object.assign({}, original) |