Last active
September 24, 2018 08:47
-
-
Save obiwankenoobi/219f83f4a7e44d772e8666c07c7f30bd to your computer and use it in GitHub Desktop.
function to deep copying an array of objects
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 copyArr = arr => arr.map(obj => JSON.parse(JSON.stringify(obj))); | |
/* | |
** %%%%%%%%%%%%EXAMPLE%%%%%%%%%%%%%%% | |
** let arr = [ | |
** { name: "arty" }, | |
** { name: "yotam" }, | |
** [1,2,3] | |
** ]; | |
** let coppyArr = deepCopiedArr(arr); | |
** coppyArr[0].name = 'not arty'; | |
** coppyArr[2] = [3,2,1]; | |
** | |
** | |
** console.log(arr[0].name); // 'arty' | |
** console.log(arr[2]); // '[1,2,3]' | |
** %%%%%%%%%%%%EXAMPLE%%%%%%%%%%%%%%% | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment