Clone object - Node.js Object

Node.js examples for Object:Object Operation

Description

Clone object

Demo Code

/**/*from   w  ww.ja  v a 2  s . c o  m*/
 * <p>
 * @param obj
 * @returns
 */
function clone(obj){
  var cloneObj;
  if((typeof obj)==='object'){
    var name;
    for(name in obj){
      if((typeof obj[name])==='Object'){
        cloneObj[name]=clone(obj[name]);
      }else{
        cloneObj[name]=obj[name];
      }      
    }
  }else{
    cloneObj=obj;
  }
  return cloneObj;
}

Related Tutorials