Function to perform a deep copy of an object - rudimentary in that it will only handle the following types:
- Primitives
- Array
- Object
Basically can perform the following, but also copy undefined
:
const clone = JSON.parse(JSON.stringify(myObj));
Also will handle circular references from the item source, such as:
const source = {
one: 1,
two: 2,
};
source.three = source;
const clone = copy(source);