I need to create arrays dynamically. Suppose I have an array
name = ['a','b','c']
each of this values will be an array with a fixed size. like
a = [null, null, null]
b = [null, null, null]
c = [null, null, null]
Afterwards, I want to access each array with the value of name array. Like
name[0] will represent the 'a' array.
const name = ['a', 'b', 'c'];
const arraysAggregator = {};
const fixedSize = 3;
name.forEach(key => {
arraysAggregator[key] = new Array(fixedSize);
//fill the content you need here
});
//test
// access to an array as per key
console.log(arraysAggregator['a'])
// if you want to receive array of arrays you can use
const arrayOfArray = [...Object.values(arraysAggregator)];
console.log(arrayOfArray);