View Full Version : problem with nested tables

02-09-2007, 02:40 PM
Hi ,
I would like to dynamically populate tables
var bloc = new Array();which contain nested arrays(with constant size)

bloc[0]= new array(10);
bloc[1]= new array(10);
// till bloc[k]

The T table containing my values are constitued from inner array with different lengths
var T= new Array();
T[0], T[1], T[2],till T[n]

I start to fill the bloc[0] with T[0] and if the length of T[0] is smaller than 10 I go on with T[1]
But I have the constraint to have unique element per bloc
I have already checked than the individual table T[0], T[1], T[n]...have unique elements

for exemple
T[0]= ['1','2','3','4','5','6','20'];
T[1]= ['30','20','10','11'];
then bloc[0]should be['1','2','3','4','5','6','20','30','10','11']

function Test(){
var k = 0; //counter of block
var j=0;// loop in block

var n=0; //counter of nested T
var i=0;// loop in T[]
var found;

bloc[0][0]=T[0][0]; //initialisation: the first element in the first bloc come from the first

elemt of T[0]

for (i=0; i<(T[n].length);i++){ //i is the counter of element in T[]

if(i%10==0)k++; //if already 10 elements in the block then a new bloc created

if (bloc[k][j] == T[n][i]) {
si element found do nothing
found = true;

if (!found){
bloc[k][bloc[k].length] = T[n][i];
// then put it in the block



The function didnot work
Problem with loop?
many thanks for your ideas

02-09-2007, 04:32 PM
you have problems not with nested tables...u must use nested loops...try again with 2 for loops
1. for the T[0], T[1] ... T[T.length]
-> 2. for the elements insided every T[n]

02-09-2007, 04:57 PM
Hi shyam
thank for the advice
but I don't know how to do it.
Can you ,please,be more explicit

I have though to do something like for
for (var i=0;i<(T[0].length);i++){
bloc[0][i] = T[i];
but I don't know how many T[n] I have
and how can I go on with the next T[]

Thank for your interest

02-09-2007, 05:21 PM
for ( i = 0; i < T.length; i++ ) {
for ( j = 0; j < T[i].length; j++ ) {
// T[i][j]
} // inner j
} // outer i

02-09-2007, 05:34 PM
thank Shyam for your explanation

function Test() {

var k = 0;

for (var i=0; i<T.length; ++i) {
for (var j=0; j<T[i].length; ++j) {
if (bloc[k].length == 10) {
bloc[k] = [];

The function looks better but I still have problem to go to the next bloc after 10 elements

02-10-2007, 09:18 AM
Now it is working
I have forgotten some '('
Thank for you helps