const products = [{
id: 5,
productName: "Logitech Mouse",
unitprice: 35
},
{
id: 6,
productName: "Logitech Keyboard",
unitprice: 40
}
];
const cart = [{
id: 101,
userId: 3,
productId: 5,
quantity: 2
},
{
id: 102,
userId: 3,
productId: 6,
quantity: 1
}
];
With these data in the objects, how do I inner join cart's productId to product's id? So that the output will be :
Logitech Mouse, 35, 2 Logitech Keyboard, 40, 1
cart.forEach(item=>item.product = products.find(product=>product.id === item.productId));Done.