Skip to content

Instantly share code, notes, and snippets.

@ionurboz
Created March 18, 2019 13:19
Show Gist options
  • Save ionurboz/01dfd03689ca74d578782eada3ac387b to your computer and use it in GitHub Desktop.
Save ionurboz/01dfd03689ca74d578782eada3ac387b to your computer and use it in GitHub Desktop.
Clone Object (Pure JS)
/**
* Return a clone of an object or array
* @param {Object|Array} obj The object or array to clone
* @return {Object|Array} An exact copy of the object or array
*/
var clone = function (obj) {
if (!obj) return;
return JSON.parse(JSON.stringify(obj));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment