Skip to content

Instantly share code, notes, and snippets.

@KentaKomai
Created November 16, 2015 10:23
Show Gist options
  • Save KentaKomai/abc7d31ecfe893839942 to your computer and use it in GitHub Desktop.
Save KentaKomai/abc7d31ecfe893839942 to your computer and use it in GitHub Desktop.
ネストしているObjectを全部コピーする
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