weymeels weymeels - 22 days ago 8
jQuery Question

problems with js table

I have a problem with my table , I need to put several variable in my table , this is my error

TypeError: tabproduit[i] is undefined

tabproduit[i][0] = $(this).text();

and this is my code

var tabproduit = new Array(new Array());
var i = 0 ;
$( ".eachnom" ).each(function( index ) {
tabproduit[i][0] = $(this).text();

however , when I don't put the
I don t have the error but I have just 1 variable in my table;

how to put this

thanks in advance


The problem is you're getting the error because js provides a single dimensional array in nature you can extend it into two dimensional by the following convention

 var s = [[],[],[]]

if not then you will get the array [ith] position always undefined

so my suggestion to you would be first get the number of rows then define

s[r1] = []; s[r2] = []... and so on may be using loop

then you will be able to do s[r1][c1] operation

hope it helps