Thank you for providing your responses. I appreciate the correct answers you shared based on the question. The error in the question was a result of my oversight, as I failed to include collecting the amount paid when combining user names. I am in the process of restructuring the code for accuracy.
const array =[
{
name: 'Iphone',
date: '01.01.2024',
img: 'img/iphone.png',
cost: 2500,
paid: 500,
username:"Joe",
},
{
name: 'Samsung',
date: '01.01.2024',
img: 'img/samsung.png',
cost: 2000,
paid: 200,
username:"Adam",
},
{
name: 'Samsung',
date: '01.01.2024',
img: 'img/samsung.png',
cost: 2000,
paid: 100,
username:"Alvin",
}
]
The data retrieved from my database requires a new arrangement to be combined effectively. Specifically, the sum of values in the Paid field needs to be calculated accordingly.
const array =[
{
name: 'Iphone',
date: '01.01.2024',
img: 'img/iphone.png',
cost: 2500,
paid: 500,
username:"Joe",
},
{
name: 'Samsung',
date: '01.01.2024',
img: 'img/samsung.png',
cost: 2000,
paid: 300, <--- accumulated paid amount from 2 Samsung entries
usernames:[
{username : "Adam"},
{username : "Alvin"}
]
}
]