Предполагая, что вы хотели получить авальный список из списка сотрудников, вы можете попробовать комбинацию map
и reduce
Карта для создания массивов массива, в которых все будут начинаться с aval.значения для конкретного сотрудника employee
-> aval
-> start
Уменьшить, чтобы сгладить массив массивов
Наконециспользуйте ES6 Set
для выбора уникальных значений.
const employees = [{
"EmployeeID": "56250f",
"FirstName": "Downs",
"aval": [{
"start": "11-19",
"end": "2",
"ava": "30",
"health": "4"
},
{
"start": "11-20",
"end": "2",
"ava": "40",
"health": "4"
},
{
"start": "11-21",
"end": "2",
"ava": "50",
"health": "4"
},
{
"start": "11-22",
"end": "2",
"ava": "60",
"health": "4"
}
]
},
{
"EmployeeID": "56250f",
"FirstName": "Mckenzie",
"aval": [{
"start": "11-19",
"end": "2",
"ava": "1",
"health": "4"
},
{
"start": "11-20",
"end": "2",
"ava": "2",
"health": "4"
},
{
"start": "11-21",
"end": "2",
"ava": "3",
"health": "4"
},
{
"start": "11-22",
"end": "2",
"ava": "4",
"health": "4"
}
]
}, {
"EmployeeID": "56250f",
"FirstName": "Charles",
"aval": [{
"start": "11-19",
"end": "2",
"ava": "100",
"health": "4"
},
{
"start": "11-20",
"end": "2",
"ava": "200",
"health": "4"
},
{
"start": "11-21",
"end": "2",
"ava": "300",
"health": "4"
},
{
"start": "11-22",
"end": "2",
"ava": "400",
"health": "4"
}
]
}
]
const mappedAvals = employees.map(emp => emp.aval.map(av => av.start));
console.log("************* MAPPED AVALS **************");
console.log(mappedAvals);
console.log("************* MAPPED AVALS **************");
const flattenedAvals = mappedAvals.reduce((acc, aval) => [...acc, ...aval], []);
console.log("************* FLATTENED AVALS **************");
console.log(flattenedAvals);
console.log("************* FLATTENED AVALS **************");
const distinctAvals = [...(new Set(flattenedAvals))];
console.log("************* DISTINCT AVALS **************");
console.log(distinctAvals);
console.log("************* DISTINCT AVALS **************");