I am currently working on a project where I need to dynamically create arrays to store elements based on certain conditions. Specifically, I want to create an array for each occurrence of a specific element (in this case, "bank"). The first occurrence should go into the first array, the second into the second array, and so on. Once all elements are placed in separate arrays, I then push them onto a main array.
My question is, can I generate these arrays with unique names dynamically, such as Bank_1, Bank_2, and so forth? And is this approach the correct way to solve this problem?
var bankcontainer = [];
var bank = [];
for(let i = 0; i < length; i++) {
let bankname = data.periods[0].decisions[i].bank;
bank[i] = [];
bank[i].push(bankname);
bankcontainer.push(bank);
}
For example:
// Input:
[{ bank: "team1" }, { bank: "team2" }, { bank: "team3" }]
// Result:
{ bank_1: ["team1"], bank_2: ["team2"], bank_3: ["team3"] }