JSFiddle - React, Tailwind, and code Playground
by jfriend00
CSS
body {font-family: "Courier New";}
JavaScript
abcArr = [["A", 10], ["B", 20], ["A",30],["C",40]]
var items = {}, base, key;
for (var i = 0; i < abcArr.length; i++) {
base = abcArr[i];
key = base[0];
if (!items[key]) {
items[key] = 0;
}
items[key] += base[1];
}
// Now, generate new array
var outputArr = [], temp;
for (key in items) {
temp = [key, items[key]]
outputArr.push(temp);
}
// outputArr contains the result
document.body.innerHTML = JSON.stringify(outputArr);