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);
players.forEach((item) => {
const len = item.holes.length;
item.holes.length = length;
item.holes.fill({score: '-'}, len, length)
console.log(item.holes);
});