const arr = [1,4,5,[6,7,8,{a:"a"}]];
function clone(obj){
if(!obj ||typeof obj !=="object") return;
let newObj = Array.isArray(obj)?[]:{};
for(let i in obj){
if(obj.hasOwnProperty(i)){
newObj[i]=obj[i];
}
};
return newObj;
}
function deepClone(obj){
if(!obj|| typeof obj !=="object") return;
let newObj = Array.isArray(obj)?[]:{};
for(let i in obj){
if(obj.hasOwnProperty(i)){
newObj[i]= typeof obj[i] ==="object" ? deepClone(obj[i]):obj[i];
}
};
return newObj;
}
let arr2=deepClone(arr);
arr2[0]=8;
arr2[3][3].a=6;
console.log(arr);
console.log(arr2);
console