Dynamically create a two dimensional Javascript Array

后端 未结 7 1783
臣服心动
臣服心动 2020-12-11 22:07

Can someone show me the javascript I need to use to dynamically create a two dimensional Javascript Array like below?

desired array contents:

7条回答
  •  独厮守ぢ
    2020-12-11 22:40

    You don't need to keep track of array lengths yourself; the runtime maintains the ".length" property for you. On top of that, there's the .push() method to add an element to the end of an array.

        // ...
        innerArray.push($(this).text());
      // ...
      outerArray.push(innerArray);
    

    To make a new array, just use []:

    innerArray = []; // new array for this row
    

    Also "outer" has only one "t" :-)

提交回复
热议问题