This question is related to this other question.
I'm sorry but I can't find the solution. I need to group an array of objects given by dataObject in this fiddle by the property objetivo with the properties: id, indicadores, objetivo and perspetiva.
This is my code:
var res = dataObject.reduce(function(res, currentValue) {
if ( res.indexOf(currentValue.objetivo) === -1 ) {
res.push(currentValue.objetivo);
}
return res;
}, []).map(function(objetivo) {
return {
objetivo: objetivo,
indicadores: dataObject.filter(function(_el) {
return _el.objetivo === objetivo;
}).map(function(_el) { return _el.indicador; }),
perspetiva: dataObject.perspetiva,
id: dataObject.id
}
});
console.log(res);
Which is grouping by objetivo correctly, but returning undefined for perspetiva and id.
Thanks for helping and sorry if this is duplicating other questions.