Sometimes you need to clone the whole object, not just the shallow version with only its top level properties. There are many ways to achieve this, but here you'll learn the most efficient one and the difference between a shallow copy and a deep copy of an object.
Shallow copy
this is my code 389
One of the most common methods used to clone an object is Object.assign({}, obj)
, or in ES6 using the spread operator.
https://stackoverflow.com/questions/38416020/deep-copy-in-es6-using-the-spread-syntax