Hello i am trying to repack array of objects and convert it into one object with specific keys. So here is array:
const entryPenaltyGroups = [
{ entryId: 16, intervalId: 8, penaltyTime: 16000 },
{ entryId: 16, intervalId: 10, penaltyTime: 6000 }
]
Expected result should be:
{
'8': {
penaltyTime: 16000
},
'10': {
penaltyTime: 6000
}
}
I have tried something with map(), but not getting expected results.
for (const entry of entryPenaltyGroups) {
entry.map(x => [{
[x.intervalId]: {
penaltyTime: x.intervalId
},
}])
}
Should i use reduce() instead maybe?
intervalId?Object.keys()with an array? Whyfor...of...? Why.map()in thefor...of...loop? Why.map()for a single element? And why is there noTypeErrorin your question that will be thrown by calling.map()on an object (entryPenaltyGroups[key].map(...))? -> How do I ask a good question?