Why is the array getting just the last object?
this.checkpoints = new Array();
this.checkpoint = new Object();
this.checkpoint['lat'];
this.checkpoint['lng'];
this.checkpoint['lat'] = 1;
this.checkpoint['lng'] = 1;
this.checkpoints.push(this.checkpoint);
this.checkpoint['lat'] = 2;
this.checkpoint['lng'] = 2;
this.checkpoints.push(this.checkpoint);
this.checkpoint['lat'] = 3;
this.checkpoint['lng'] = 3;
this.checkpoints.push(this.checkpoint);
console.log(this.checkpoints);
The result is wrong:
[Object { lat=3, lng=3}, Object { lat=3, lng=3}, Object { lat=3, lng=3}]
But if I try without objects, it's OK:
this.checkpoints = new Array();
this.checkpoints.push(1);
this.checkpoints.push(2);
this.checkpoints.push(3);
console.log(this.checkpoints);
The result is:
[1, 2, 3]
Please, what am I missing? Thanks in advance!
this.checkpoint's address (reference), not it's value.this.checkpoint['lat']; this.checkpoint['lng'];do