javascript - How can I get the length of a multidimensional array -
i have array follows:
$('#mmtable').data('armsitems').push([[],[],[]]); $('#mmtable').data('armsitems')[0][0]['productnr'] = 1; $('#mmtable').data('armsitems')[0][0]['title'] = 1; $('#mmtable').data('armsitems')[0][0]['description'] = 1; $('#mmtable').data('armsitems').push([[],[],[]]); //------------------------------------------------- $('#mmtable').data('armsitems')[1][0]['productnr'] = 1; $('#mmtable').data('armsitems')[1][0]['title'] = 1; $('#mmtable').data('armsitems')[1][0]['description'] = 1; $('#mmtable').data('armsitems').push([[],[],[]]); //------------------------------------------------- $('#mmtable').data('armsitems')[2][0]['productnr'] = 1; $('#mmtable').data('armsitems')[2][0]['title'] = 1; $('#mmtable').data('armsitems')[2][0]['description'] = 1; alert( $('#mmtable').data('armsitems')[0][0].length ); // results --> 3 //------------------------------------------------- $('#mmtable').data('armsitems').push([[],[],[]]); $('#mmtable').data('armsitems')[0][1]['productnr'] = 1; $('#mmtable').data('armsitems')[0][1]['title'] = 1; $('#mmtable').data('armsitems')[0][1]['description'] = 1; $('#mmtable').data('armsitems').push([[],[],[]]); //------------------------------------------------- $('#mmtable').data('armsitems')[1][1]['productnr'] = 1; $('#mmtable').data('armsitems')[1][1]['title'] = 1; $('#mmtable').data('armsitems')[1][1]['description'] = 1; alert( $('#mmtable').data('armsitems').length ); // results --> 5 //----------------------------------------------------------------
how can number of elements in second field? e.g. :
[0][1]['productnr'] [1][1]['productnr']
i expect result 2-elements. how can it?
e.g. second field "1" follows: [x][1][x]
alert( $('#mmtable').data('armsitems')[x][1][x].length );
how many elements array contain (i expect result 2) ?
many in advance.
logically array should like,
['armsitems']['productnr'][0] ['armsitems']['title'][0] ['armsitems']['description'][0] ['armsitems']['productnr'][1] ['armsitems']['title'][1] ['armsitems']['description'][1] // on..
then can length using,
alert(arr['armsitems']['productnr'].length);
Comments
Post a Comment