JSFiddle - React, Tailwind, and code Playground
HTML
<table>
<tr class="Violão">
<td>Violão</td>
<td class="td2 8">8</td>
</tr>
<tr class="Violão">
<td>Violão</td>
<td class="td2 23">23</td>
</tr class="Violão">
<tr class="Guitarra">
<td>Guitarra</td>
<td class="td2 16">16</td>
</tr>
</table>
JavaScript
var dictionary = [];
$("table tr").each(function() {
var thisName = $(this).attr("class");
if ($.inArray(thisName, dictionary) == -1) {
dictionary.push(thisName);
}
});
for(var obj in dictionary) {
var className = dictionary[obj];
var total = 0;
$("table tr." + className).each(function() {
total += parseInt($(this).children(".td2").text());
});
$("table tr." + className).append("<td>Total: " + total + "</td>");
}