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
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.