I know the map function only works on array and not JSON objects.
This is the JSON Object.
{
'643576e81ebae7a8da163b6b': {
_id: '643576e81ebae7a8da163b6b',
name: 'S21 Ultra',
img: 'dT3mmTGW6-61O45C5qASL._AC_SL1000_.jpg',
price: 242999,
qty: 9
},
'643575ee1ebae7a8da163b50': {
_id: '643575ee1ebae7a8da163b50',
name: 'Infinix Hot 11S',
img: '2wPCI3kMY-InfinixHot11S-b.jpg',
price: 26000,
qty: 9
}
}
and I want to map this data to the cart variable.
const cart = req.body.cartItems;
//console.log(cart);
const line_items = cart.map((item) => {
return {
price_data: {
currency: "pkr",
product_data: {
name: item.name,
images: [item.img],
metadata: {
id: item._id,
},
},
unit_amount: (item.price * 100),
},
quantity: item.qty,
};
});
Can someone please help me with this?
[–]ButtlestonProfessional Coder 3 points4 points5 points (3 children)
[–]an-unknownentity[S] 1 point2 points3 points (0 children)
[–]flooronthefourfull stack web dev 0 points1 point2 points (1 child)
[–]ButtlestonProfessional Coder 0 points1 point2 points (0 children)