When prod is pushed into prodObj, description in all other similar objects are updated to its last instance. While prod itself is just fine and all keys description are with its own value
let prodObj = [];
for (let i = 0; i < product.length; i++){
for (let j = 0; j < cartRegistry.length; j++){
if ( cartRegistry[j].ProductId === (product[i]._id.toString()) ){
var prod = product[i];
prod.description = parseInt(cartRegistry[j].Quantity);
console.log(prod);
prodObj.push(prod);
}
}
}
prod ex:
_id: new ObjectId("62a52831c42a0fb4730283f4")
name: 'RJ45',
image: 'cable.jpg',
description: '2',
_id: new ObjectId("62a52831c42a0fb4730283f4")
name: 'RJ45',
image: 'cable.jpg',
description: '1',
ProdObj which was supposed to have the same values updates both description keys to 1, the last instance of it
Same with all other objects except they have different values