I'm trying to add my loop data to an object.
subItem.allAvgObj = {};
for(var i = 0; i < subItem.implementations.length; i++) {
if (subItem.implementations[i].avg_score) {
Object.assign(subItem.allAvgObj, {
scoreAvg: subItem.implementations[i].avg_score,
scorePonderation: subItem.implementations[i].ponderation,
})
}
}
Only, there is only the last object of my loop that is assigned.
{
"scoreAvg": 8,
"scorePonderation": 10
}
I tried with an array, and it works (but it's an array with a single value, but the loop works)
subItem.allAvgArray.push(subItem.implementations[i].avg_score);
Return :
[
13.5,
16,
8
]
How can I make an object like this?
{
"scoreAvg": 13.5,
"scorePonderation": 20
},
{
"scoreAvg": 16,
"scorePonderation": 20
},
{
"scoreAvg": 8,
"scorePonderation": 10
}
Thank you