Im looping through an array of objects and returning an array from each object.
for (i = 0; i < allStageData.length; i++) {
dataArray = allStageData[i].stagesCount;
console.log(dataArray);
}
dataArray returns 15 arrays with 6 integers in each.
[44, 103, 50, 5, 4, 30],
[2, 12, 4, 29, 7, 93],
...
..
.
I would like to dynamically create 6(length of stagesCount) new arrays with 15(length of allStageData) items in each. So the first array would contain the first element from all the dataArrays, second would contain the second element and so on.
let keys= [];
for (i = 0; i < allStageData.length; i++) {
dataArray = allStageData[i].stagesCount;
keys.push(allStageData[i].stagesCount[0]);
}
Keys returns the first item in each array but I'm looking for something more dynamic.
for (i = 0; i < allStageData.length; i++) {
dataArray = allStageData[i].stagesCount;
for (j = 0; j < allStageData[i].stagesCount.length; j++) {
keys = allStageData[i].stagesCount[j];
console.log('keys ' + j);
console.log(keys);
}
}
Here keys returns :
keys 0
44
keys 1
103
keys 2
50
keys 3
5
keys 4
4
keys 5
30
keys 0
2
keys 1
12
keys 2
4
keys 3
29
keys 4
7
keys 5
93
...
..
.
How would I push all of the keys with the same j index of 0 in one array, all of the keys with the same j index of 1 into another array, and so forth?
Is there a better solution completely than my approach?
Any help is greatly appreciated.