s24344,
const data = [
{
locations: [
{
locationId: 0,
players: [
{
holes: [
{
holeId: 1,
score: 5
},
{
holeId: 2,
score: 5
},
{
holeId: 3,
score: 5
},
{
holeId: 4,
score: 5
}
],
firstName: "firstName 1",
lastName: "lastName 1"
},
{
holes: [
{
holeId: 1,
score: 5
},
{
holeId: 2,
score: 5
}
],
firstName: "firstName 2",
lastName: "lastName 2"
},
{
holes: [
{
holeId: 1,
score: 5
}
],
firstName: "firstName 3",
lastName: "lastName 3"
}
]
}
]
}
]
const players = data[0].locations[0].players;
const length = players.reduce((max, item) => {
const {length} = item.holes;
return Math.max(max,length);
},0);
const arr = Array.from(new Array(length), () => ({score: '-'}));
players.forEach((item) => {
item.holes = Object.assign([], arr, item.holes)
console.log(item.holes);
});