estoy intentando armar un arreglo que muestre valores únicos y sumas totales.
Estoy tomando este arreglo que contiene los siguientes valores:
[Array]
0: {name: "16", value: "1"}
1: {name: "16", value: "1"}
2: {name: "16", value: "1"}
3: {name: "15", value: "8"}
4: {name: "15", value: "8"}
5: {name: "15", value: "8"}
6: {name: "15", value: "8"}
7: {name: "15", value: "8"}
8: {name: "15", value: "8"}
9: {name: "15", value: "8"}
10: {name: "14", value: "3"}
11: {name: "14", value: "3"}
12: {name: "14", value: "3"}
13: {name: "14", value: "3"}
14: {name: "23", value: "1"}
15: {name: "23", value: "1"}
16: {name: "23", value: "1"}
17: {name: "22", value: "1"}
18: {name: "22", value: "1"}
19: {name: "22", value: "1"}
20: {name: "15", value: "1"}
21: {name: "15", value: "1"}
22: {name: "23", value: "1"}
23: {name: "23", value: "1"}
24: {name: "23", value: "1"}
25: {name: "23", value: "1"}
26: {name: "22", value: "1"}
27: {name: "22", value: "1"}
28: {name: "22", value: "1"}
29: {name: "01", value: "1"}
30: {name: "01", value: "1"}
31: {name: "01", value: "1"}
32: {name: "01", value: "1"}
33: {name: "16", value: "2"}
34: {name: "16", value: "2"}
35: {name: "16", value: "2"}
36: {name: "16", value: "2"}
37: {name: "16", value: "2"}
38: {name: "16", value: "2"}
39: {name: "14", value: "2"}
Estoy tratando que quede algo si:
Lo estoy intentando con siguiente codigo:
public Array2 = [];
var cantidad = 0;
Array.map((i) => {
if (i.name == i.name) {
cantidad = cantidad + parseInt(i.value);
this.Array2.push({
name: i.name,
value: i.value,
});
}
});
Pero cuando lo ejecuto me repite los mismo valores de name y me suma mal los values.
No se, si existirá alguna forma o algun metodo para representar lo que quiero en el array