Files
30-seconds-of-code/snippets/shallowClone.md
Angelos Chalaris 8281457945 Updated examples
Removed duplicate and unnecessary examples.
2018-01-04 14:22:56 +02:00

290 B

shallowClone

Creates a shallow clone of an object.

Use Object.assign() and an empty object ({}) to create a shallow clone of the original.

const shallowClone = obj => Object.assign({}, obj);
const a = { x: true, y: 1 };
const b = shallowClone(a); // a !== b