Last active
December 15, 2015 01:49
-
-
Save ElfhirDev/5182579 to your computer and use it in GitHub Desktop.
JavaScript Multidimension Array Ctor
Since creating a two dimensions array in JavaScript is a pain - for me - thanks to Matthew Crumley on Stackoverflow - this constructor of Array matches my idea of multi dimension array ctor.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createArray(length) { | |
var a = new Array(length || 0); | |
if (arguments.length > 1) { | |
var args = Array.prototype.slice.call(arguments, 1); | |
for (var i = 0; i < length; i++) { | |
a[i] = createArray.apply(this, args); | |
} | |
} | |
return a; | |
} | |
// For instance, a 4 rows 6 columns array | |
var rectangles = createArray(4, 6); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment