//var arr = [1,2,[11,22]];
var arr = {
name:"xiao",
age:{
first:"diyi",
two:"第二"
}
};
function deepCopy(parm){
let res;
if(Object.prototype.toString.call(parm) == "[object Array]"){ //数组
res = [];
for(var i = 0;i < parm.length;i++){
res[i] = deepCopy(parm[i]);
}
}else if(Object.prototype.toString.call(parm) == "[object Object]"){ //对象
res = {};
for(var i in parm){
res[i] = deepCopy(parm[i]);
}
}else{
return parm;
}
return res;
}
var newarr = deepCopy(arr);
//arr[1] = "xx";
arr.name = "gejin";
console.log(newarr);
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。