Deep copy object - Node.js Object

Node.js examples for Object:Object Operation

Description

Deep copy object

Demo Code

function deepCopy(p,c) {
  var c = c||{};//from  w w  w  .ja va2 s . co m
  for (var i in p) {
    if (typeof p[i] === 'object')
    {
      c[i] = (p[i].constructor === Array)?[]:{};
      deepCopy(p[i],c[i]);
    } else c[i] = p[i];
  }
  return c;
}

Related Tutorials