JSFiddle - React, Tailwind, and code Playground

by jasonblewis

HTML

<p id="demo">

</p>

JavaScript

var sumcols = [2,3,6];
var data = [
    ["S",10,20,30,40,50,60,70,80,90],
    ["P",11,21,33,44,24,24,70,80,90],
    ["S",12,21,33,43,43,42,43,43,43],
    ["P",13,21,32,32,32,32,37,78,02],
    ["S",14,53,53,15,43,64,64,26,32],
    ["P",15,32,43,14,21,32,32,32,32],
    ["S",14,24,31,32,32,32,23,43,42],
    ["P",17,32,43,24,21,32,43,14,20],
    ["S",18,31,43,14,24,34,24,34,20],
];

var total = {S: 0,P:0,GrandTotal:0};

data.forEach(function(row,rownum){
    //console.log(row);
    sumcols.forEach(function(item,index){
        total[index] = total[index] + row[item];
    });
    console.log("total: ", total);
});