const arr = [{
firstName: "Noah",
lastName: "M.",
country: "Switzerland",
continent: "Europe",
age: 19,
language: "C",
year: 2019,
},
{
firstName: "Anna",
lastName: "R.",
country: "Liechtenstein",
continent: "Europe",
age: 52,
language: "JavaScript",
year: 2019,
},
{
firstName: "Piter",
lastName: "G.",
country: "Sweden",
continent: "Europe",
age: 30,
language: "JavaScript",
year: 2019,
}]
const fun = (arr) => {
return arr.reduce((acc, value, i) => {
if (value.year === 2019) {
return { ...acc, [value.language]: i };
}
return acc;
}, {});
};
в консоли выводится
C: 0
JavaScript: 2
должно быть
C: 1
JavaScript: 2