I am trying to send variable Quantity to another object that shares the same ID for Product. (I am using MongoDB) It even logs the result specified below but then an error happens
for (let i = 0; i < product.length; i++){
for (let j = 0; j < cartRegistry.length; j++){
if ( cartRegistry[i].ProductId === (product[j]._id.toString()) ){
console.log(product[j]._id.toString())
console.log(cartRegistry[i].ProductId, product[j]._id)
console.log('true')
}
/* console.log(quantity[i].id === product[j]._id.toString()) */
}
}
C:\Users\Toni\Documents\Aulas Node\store\routes\cart.js:22 if ( cartRegistry[i].ProductId === (product[j]._id.toString()) ){ ^
TypeError: Cannot read properties of undefined (reading '_id') at C:\Users\Toni\Documents\Aulas Node\store\routes\cart.js:22:60