0

Is it possible to dynamically create an array from a function by assigning an array with a variable name?

for (var i = 1; i <= noDatasets; i++) {
    var ["myArray"+i] = new Array();
}

Then in a later function, i'd like to be able access and push items into this array.

for (var i = 1; i <= noDatasets; i++) {
    ["myArray"+i].push('1', '2', '3');
}

I've had various attempts and nothing worked. The challenge is I dont want to hard code the number of arrays to be created given the number of arrays required depends on the outcome of other operations in my app, thx

OJB1
  • 1,494
  • 1
  • 18
  • 42

0 Answers0