Files
30-seconds-of-code/snippets/shallowClone.md
2020-09-15 21:52:00 +03:00

325 B

title, tags
title tags
shallowClone object,beginner

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