[Solved] Group a array by another array using JavaScript [closed]


If by group by you mean adding values with same keys together you could try:

let a = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'A', 'F', 'C', 'A', 'E'];
let b = ['5', '7', '4', '3', '8', '1', '9', '1', '5', '4', '2', '10'];

const temp = {};
a.forEach((value, index) => {
    temp.hasOwnProperty(value) ? temp[value]+=parseInt(b[index]) : temp[value]=parseInt(b[index]);
});

a = Object.keys(temp);
b = Object.values(temp);
console.log(a, b);

solved Group a array by another array using JavaScript [closed]