array conversion error in jquery showing

array conversion error in jquery showing

hi following is a working example

var totals = [0, 0, 0, 0, 0, 0];
            var $dataRows = $("#GridViewProfit tr:not('.totalColumn, .titlerow')");
            $dataRows.each(function () {
                $(this).find('.rowDataSd').each(function (i) {
                    var k = parseInt($(this).html());
                    if ($(this).html() != '') {

                        totals[i] += parseInt($(this).html());
                        console.log(totals[i]);
                        // $("#GridViewProfit tr:last td").eq(i + 1).html(totals[i]).css('background-color', 'white');
                    }
                });
            });
            $("#GridViewProfit td.totalCol").each(function (i) {
                $(this).html("total:" + totals[i]);
            });
 

this is for calculating sum of each column in an html table.

here iam directly declare totals as

var totals=[0,0,0,0,0,0];

my requirement is to create totals dynamically

like following code



 
var totals;
            var l = $('#GridViewProfit tr th').length - 1;
            var str = '[';
            for (k = 0; k < l; k++) {
                str += 0 + ' ,';

            }

           // alert(totals);
            var bb = str;
            bb = bb.slice(0, -1);
            bb += ']';
            totals = bb;

 

here iam getting bb=[0,0,0,0,0,0];

i convert into totals=bb;

but this is not working

How to solve this

Regards

Baiju