Tengo el siguiente código pero no veo claro el porqué del acc[student.name]
y del , {}
del final, con números lo veo pero no entiendo porque []
para acceder al estudiante cuando pensé que sería con .
:
var students = [{
name: "Tony Parker",
firstProject: 80,
secondProject: 75,
finalExam: 90,
age: 25,
skills: ['C', 'Java', 'JavaScript']
},
{
name: "Marc Barchini",
firstProject: 84,
secondProject: 65,
finalExam: 65,
age: 30,
skills: ['Swift', 'JavaScript']
},
{
name: "Claudia Lopez",
firstProject: 45,
secondProject: 95,
finalExam: 99,
age: 49,
skills: ['Java', 'Pearl']
},
{
name: "Alvaro Briattore",
firstProject: 82,
secondProject: 92,
finalExam: 70,
age: 24,
skills: ['JavaScript', 'PHP']
},
{
name: "Isabel Ortega",
firstProject: 90,
secondProject: 32,
finalExam: 85,
age: 21,
skills: ['Lua', 'Python']
},
{
name: "Francisco Martinez",
firstProject: 90,
secondProject: 55,
finalExam: 78,
age: 45,
skills: ['C++', 'Python']
},
{
name: "Jorge Carrillo",
firstProject: 83,
secondProject: 77,
finalExam: 90,
age: 32,
skills: ['C#', 'C++', 'C']
},
{
name: "Miguel López",
firstProject: 80,
secondProject: 75,
finalExam: 75,
age: 31,
skills: ['Scala', 'Java']
},
{
name: "Carolina Perez",
firstProject: 85,
secondProject: 72,
finalExam: 67,
age: 27,
skills: ['Scala', 'Java', 'JavaScript']
},
{
name: "Ruben Pardo",
firstProject: 89,
secondProject: 72,
finalExam: 65,
age: 28,
skills: ['C#', 'JavaScript']
}
]
var result = students.reduce(function(acc, student) {
acc[student.name] = student.age;
return acc;
}, {});
console.log(result);