Created
April 11, 2013 22:49
-
-
Save rd13/5367834 to your computer and use it in GitHub Desktop.
Javascript function to pre-populate multiple 2D arrays
This file contains 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
populateEmptyArrays = function(vars, num) { | |
//Function to pre-populate multiple 2D arrays | |
//vars = Array of variable names to pre-populate with arrays | |
//num = Array size | |
if(!(vars instanceof Array) || isNaN(num)) return; | |
for(i in vars) { | |
window[vars[i]] = (function(a){ while(a.push([]) < num); return a})([]) | |
} | |
} | |
populateEmptyArrays(['A','B','C'], 6); | |
console.log(A); //[[], [], [], [], [], []] | |
console.log(B); //[[], [], [], [], [], []] | |
console.log(C); //[[], [], [], [], [], []] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment