Skip to content

Instantly share code, notes, and snippets.

@dmjcomdem
Created September 13, 2018 08:18
Show Gist options
  • Save dmjcomdem/d679c0e2ca028858636f509900f1bce7 to your computer and use it in GitHub Desktop.
Save dmjcomdem/d679c0e2ca028858636f509900f1bce7 to your computer and use it in GitHub Desktop.
Полная копия объекта
const deepClone = obj => {
let clone = Object.assign({}, obj);
Object.keys(clone).forEach(
key => (clone[key] = typeof obj[key] === 'object' ? deepClone(obj[key]) : obj[key])
);
return Array.isArray(obj) ? (clone.length = obj.length) && Array.from(clone) : clone;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment