How to create empty 2d array in javascript?

后端 未结 8 1606
执笔经年
执笔经年 2020-12-08 07:07

How do I create an empty 2D array in Javascript (without knowing how many rows or columns there will be in the new array)?

If it\'s a simple array var newArra

8条回答
  •  时光取名叫无心
    2020-12-08 07:29

    This also works as an expression:

    var twoDarr= new Array(desiredLength);
    for (i=0;i

    I don't know how it pars in terms of performance with the rest of the answers here, if you have a clue let me know in the comments.

    If you don't know the length of the array beforehand pls have in mind that you can use either push([]), or splice() if you want to push/remove/replace a new element in place of an existing one.

提交回复
热议问题