I have the following array of objects I want to add the ages of all the people:
let personas = [
{id: 1, name:'Darinel', edad: 24, lastName:'Cigarroa', ciudad: 'CDMX'},
{id: 2, name:'Darwin', edad: 24, lastName:'De jesus', ciudad: 'CDMX'},
{id: 3, name:'Vera', edad: 24, lastName:'Dominguez', ciudad: 'CDMX'},
{id: 4, name:'Emiliano', edad: 24, lastName:'Silva', ciudad: 'CDMX'},
{id: 5, name:'Derky', edad: 24, lastName:'Wilner', ciudad: 'CDMX'},
{id: 6, name:'Juan', edad: 24, lastName:'De La Cruz', ciudad: 'CDMX'},
];
I am trying this way but without any result:
let reduce = personas.reduce((acumulador, actual) => acumulador.edad + actual.edad);
console.log(reduce)
You are almost correct. The accumulator in this case will be an integer, not an object (it has no age property) and you must give it a start value (in this case 0)
Looping through the object with the forEach() method and accumulating into variables.