Skip to content

Instantly share code, notes, and snippets.

@mainanick
Last active October 14, 2018 13:08
Show Gist options
  • Save mainanick/f3952d1c9633ae1210381b4dc3e9363a to your computer and use it in GitHub Desktop.
Save mainanick/f3952d1c9633ae1210381b4dc3e9363a to your computer and use it in GitHub Desktop.
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