const product_list=[{id:1},{id:2}]
const temp_products=[{id:1,quantity:10},{id:2,quantity:20}]
product_list.map(prod=>{
console.log(temp_products.reduce((init,curr_prod)=>{
return curr_prod.id == prod.id ? curr_prod.quantity : null
}))
})
// null
// 20
The condition for the second object evaluates to true, but unfortunately, for the first object, it evaluates to false when it should be true.
The reduce function successfully retrieves the quantity from the second object, however, for the first object, it returns null instead. Why is this happening?