[Solved] Javascript; nested for-loop not working


  1. Arrays are 0-indexed, This means that the last element of an array is not at array.length but at array.length - 1.
  2. You’ll have to create a new array (sub-array) and then start adding elements to it.

Your code should be like this:

var divs = [];
for (var x = 0; x < nodeArray.length; x++) {
//          here ^^^
    divs[x] = []; // create a new sub-array (or divs.push([]);)
    for (var q = 0; q < nodeArray.childElementCount; q++) {
    //          here ^^^
        divs[x][q] = nodeArray[x].childNodes[q].childNodes[0];
    };
};

solved Javascript; nested for-loop not working