I've got the following array
arr = [
{ 'Atencion Personalizada': 2, 'Caja': 3 },
{ 'Atencion Personalizada': 1 },
{ 'Tarifa Social': 3 }
]
Expected output: 9
And I would like to sum the properties the shortest way possible. The thing is that the object keys are always variable so i can't go for:
arr.reduce((acc,item) => acc+item.keyName)
Found this post but can't adapt the code to my solution either:
var data = [{ A: 4, B: 2 }, { A: 2, B: 1 }, { A: 3, B: 1 }, { A: 2, B: 1, C: 1 }],
result = data.reduce((r, o) => (Object.entries(o).forEach(([k, v]) => r[k] = (r[k] || 0) + v), r), {});
Thank you in advance