var p = {
id: null
};
for (var copyArray = [], i = 0; i < 3; i++) {
copyArray.push(p);
copyArray[i].id = (copyArray.length) - parseInt(1, 10);
}
console.log(copyArray);
All id in copyArray is getting 2 value. Result CopyArray({id=2},{id=2},{id=2})
Doing normal push operation of object in array, and updating the index after insertion.
But somehow all id's in the copy array are getting same id What wrong i am doing over here
parseInt(1, 10)is just a long-winded and inefficient way to write1.parseIntis for parsing strings as integers.2,8,16for binary, octal, hex respectively