Layered Array in jQuery

how can i create a layered array in jQuery. This is what I have, but I'm sure I'm wrong.

newTutorial[0]['header'] = 'some header';
newTutorial[0]['text'] = 'some text';

newTutorial[1]['header'] = 'some header';
newTutorial[1]['text'] = 'some text';

...

and I need such a thing for more than 17 elements

+4
source share
3 answers

If I understand your question correctly, you can do something like the following

var times = 17; // you can define times over here 


for (var i = 0 ; i < times; i++) {
    newTutorial[i]['header'] = 'some header';
    newTutorial[i]['text'] = 'some text';

}
+4
source

Or just with do-whileloop

var i=0;
do {
    newTutorial[i]['header'] = 'some header';
    newTutorial[i]['text'] = 'some text';
    i++;
}
while (i < 17);
+3
source

If you want to insert the same value into each Index, you can do the following:

var newTutorial = new Array();
for (var i = 0; i < 17; i++) {
  newTutorial[i] = new Array();//need to define array at each index
  newTutorial[i]['header'] = 'some header';
  newTutorial[i]['text'] = 'some text';
}
+1
source

All Articles