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 newArray = new Array();
I can assign as many elements as I want. But what about a 2D array? Can I create one without specifying the numbers of rows and columns? and how do I access the elements afterwards (myArray[0][1]
or myArray[0,1]
)?
var row_major = Array(height).map(function () { return Array(width); });
would do the trick, but finally needed a 2D array today and found that it doesn't. Damn. – Mark K Cowan Jun 11 '14 at 18:51