Having trouble displaying the cart page showcasing the products added by users. I have two arrays: one containing product details and another with cart product details showing product IDs and quantities selected by users.
productDetails: [
{
productID: 1,
productTitle: 'Product Title 1',
productPrice: 2000
},
{
productID: 2,
productTitle: 'Product Title 2',
productPrice: 5000
},
{
productID: 3,
productTitle: 'Product Title 3',
productPrice: 1000
},
{
productID: 4,
productTitle: 'Product Title 4',
productPrice: 10000
}
],
CartProducts array contains:
cartProducts: [
{
productID: 1,
quantity: 5,
},
{
productID: 3,
quantity: 2,
}
]
I have successfully filtered all the products that the user has selected. Function below provides the details of products with ID 1 and 3, but now I want to merge this information into a new array adding the quantity attribute as well.
newArray: [
{
productID: 1,
productTitle: 'Product Title 1',
productPrice: 2000,
quantity:5
},
{
productID: 3,
productTitle: 'Product Title 3',
productPrice: 1000,
quantity:5
}
]
I hope my query is clear. I am attempting to solve this using the map method in JavaScript without success.
Best Regards,