Created
March 18, 2019 13:19
-
-
Save ionurboz/01dfd03689ca74d578782eada3ac387b to your computer and use it in GitHub Desktop.
Clone Object (Pure JS)
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
/** | |
* 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