Pages

deepCopy

function deepCopy(p, c={}){
  
  for (let i in p){
    if (p.hasOwnProperty(i)){
      if (typeof p[i] ==="object"){
        c[i] = Array.isArray(p[i]) ? [] : {};
        deepCopy(p[i], c[i]);
      }
      else {
        c[i] = p[i];
      }
    }
  }
  return c;

}

let u = [1,[1,2],3];

let c = deepCopy(u);

console.log(u);


code