Created
November 16, 2015 10:23
-
-
Save KentaKomai/abc7d31ecfe893839942 to your computer and use it in GitHub Desktop.
ネストしているObjectを全部コピーする
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
export default const cloneObject = function(obj){ | |
var Clone = {}; | |
for(var i in obj){ | |
console.dir(typeof obj[i]); | |
if( obj[i] instanceof Array){ | |
Clone[i] = obj[i].map( o => {return cloneObject(o)}) | |
} | |
else if(typeof obj[i] == "object"){ | |
Clone[i] = cloneObject(obj[i]); | |
} | |
else{ | |
Clone[i] = obj[i]; | |
} | |
} | |
return Clone; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment