Last active
October 14, 2018 13:08
-
-
Save mainanick/f3952d1c9633ae1210381b4dc3e9363a to your computer and use it in GitHub Desktop.
This file contains 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 has = (obj, key) => Object.hasOwnProperty.call(obj, key); | |
let deepCopy = (obj, res) => { | |
let keys = Object.keys(obj); | |
let result = res || {}; | |
keys.forEach(key => { | |
if ('object' != typeof obj[key] && has(obj, key)) { | |
result[key] = obj[key]; | |
} else { | |
result[key] = deepCopy(obj[key]); | |
} | |
}); | |
return result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment