title: Copying of an array of objects to another Array without object reference in javascript(Deep copy)
body: <p>I have a scenario where i need to copy the array of Objects(Main array) to another Temp array which should not have object reference basically if i make any modification to  Main array it should not reflect in the Temp array so that i will preserve the copy independently.</p>
  
  <p>I have used one of the code snippet from stack overflow this one does partially like if i delete all objects from the Main array the temp array still hold the value but when i do some modifications in main array and click cancel button iam removing all objects from the main array using array.Removeall(); but the modification still exist in Temp array so which means that object having a reference.</p>
  
  <pre><code>clone: function (existingArray) {
    var newObj = (existingArray instanceof Array) ? [] : {};
    console.debug('newObj value is ' + newObj);
    for (i in existingArray) {
      console.debug('i value is' + i);
      if (i == 'clone') continue;
      console.debug('existingArray[i] value ' + existingArray[i]);
      if (existingArray[i] &amp;&amp; typeof existingArray[i] == "object") {
  
        newObj[i] = this.clone(existingArray[i]);
      } else {
        console.debug('in else part ' + existingArray[i]);
        newObj[i] = existingArray[i];
      }
    }
    return newObj;
  }
  </code></pre>
  
  <p>my object structure is like</p>
  
  <p>iam using knockout framework.</p>
  
  <pre><code>newObjectCreation = function (localIp, RemoteIp, areaId) {
    this.localIP = ko.observable(localIp);
    this.remoteIP = ko.observable(RemoteIp);
    this.areaId = ko.observable(areaId);
  };
  
  template.ProtocolArray.push(new newObjectCreation('', '', '')); // to create default row
  </code></pre>
  
  <p>please help me in this regard.
  Thanks in advance.</p>