1

I am facing problems while creating another reference of a parent object list and making changes in it.eg

var cars = new Array();

var addCar = function(name,model) {
    this.name = name;
    this.model = model;
}

var car1 = new addCar("indica", "v2");
var car2 = new addCar("swift", "DLX");
var car1 = new addCar("innova", "HX");

cars.push(car1);
cars.push(car2);
cars.push(car3);

Now if we copy cars object in another object in fresh object and make changes in child object. The changes get reflected in the cars list array.

rid
  • 61,078
  • 31
  • 152
  • 193
Puneet
  • 325
  • 1
  • 12
  • 4
    Because you're not actually copying them, you're just referencing them... – Lee Taylor Nov 09 '15 at 12:13
  • 1
    http://stackoverflow.com/questions/18359093/how-to-copy-javascript-object-to-new-variable-not-by-reference?answertab=votes#tab-top – Lee Taylor Nov 09 '15 at 12:16
  • Which is a duplicate of http://stackoverflow.com/questions/122102/what-is-the-most-efficient-way-to-clone-an-object – mplungjan Nov 09 '15 at 12:24

0 Answers0