Array Conversion problem in jquery

Posted by Klbaiju under jQuery on 8/23/2016 | Points: 10 | Views : 1595 | Status : [Member] | Replies : 0
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');
}
});
})
;
This code is for calculate the sum of values in columns and display at the bottom of each columns
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 str;
var l = $('#GridViewProfit tr th').length - 1;
str = '[';
for (k = 0; k < l; k++) {
str += "0" + ' ,';

}

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

here iam getting totals=[0,0,0,0,0,0]
but it is not working
i have checked totals using console.log and alert then it is showing [0,0,0,0,0,0]
when i check with debugger in IE
then totals showing as "[0,0,0,0,0,0]"
both quotes are not showing in console.log and alert
how to solve this

Regards
Baiju




Responses

(No response found.)

Login to post response