Is there any better way to push something to undefined index in array instead of this:
// Just an example
let array = [];
let indexInArray = 0;
let data = "data";
// This throws error
// array[indexInArray].push(data);
for(let i = 0; i <= 1; i++) {
if(array[indexInArray] == undefined) {
array[indexInArray] = [data];
} else {
// This throws error if i = 0
array[indexInArray].push(data);
}
}
// array = [["data", "data"]];
I am looking for pushing to undefined index in array.
So I need to create array in index and then do push().