Created
September 13, 2018 08:18
-
-
Save dmjcomdem/d679c0e2ca028858636f509900f1bce7 to your computer and use it in GitHub Desktop.
Полная копия объекта
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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