Files
30-seconds-of-code/snippets/shallow-clone-object.md
Thomas Broadley 624a8fb2c6 Fix typos
2017-12-15 07:30:03 -05:00

260 B

Shallow clone 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 -> false
*/