Skip to content

Instantly share code, notes, and snippets.

@silentmatt
Created June 17, 2009 18:09
Show Gist options
  • Save silentmatt/131398 to your computer and use it in GitHub Desktop.
Save silentmatt/131398 to your computer and use it in GitHub Desktop.
easily create multidimensional arrays in JavaScript
function createArray(length) {
var a = new Array(Number(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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment