Suppose I have a array like this.
const info = [
{
productId: "1",
name: "This is product name 1",
sellerId: "12",
price: 30,
},
{
productId: "2",
name: "This is product name 2",
sellerId: "12",
price: 50
},
{
productId: "3",
name: "This is product name 3",
sellerId: "13",
price: 50
}
]
**This is dynamic array. Array value can be changed.
Now I have to combine this array or filter this array. I have not any idea about how can I write function. But my result will be like this-
const result = [
{
sellerId: "12",
productIds: [ //Combine products by similar sellerId
{
name: "This is product name 1",
productId: "1"
},
{
name: "This is product name 2",
productId: "2"
}
],
total: 80 //Total price of this two product
},
{
sellerId: "13",
productIds: [
{
name: "This is product name 3",
productId: "3"
}
],
total: 50
}
]
Please do not close my question. I almost check all similar questions. But I have a different issue here. Just please help me.
infoarray likeresultarray.