This is the data being sent from the server:
[[10031,2],[10054,1],[10141,3],[10247,4],[10266,1],[10278,1],[10336,1],[10509,5],[10743,2],[12159,3],[12185,2],[12186,2],[12189,1],[12233,1],[12271,2],[12335,1],[12520,3],[12521,5],[12541,1]]
The 5-digit number is an ID, and the single digit number is a quantity. If there were keys, it would be easier to access, but I only have values. I want to access the ID and the quantity separately. I also want to put all IDs into one array, and all quantities into a parallel array.
Here is what I have tried so far that sort of accesses the values separately:
for (let i = 0; i < this.state.chartData.length; i++) {
for (let j = 0; j < this.state.chartData[i].length; j++) {
console.log(this.state.chartData[i][j]);
}
}
The above code returns this in the console:
10031
2
10054
1
10141
3
10247
4
10266
1
10278
1
10336
1
10509
5
10743
2
12159
3
12185
2
12186
2
12189
1
12233
1
12271
2
12335
1
12520
3
12521
5
12541
1
Trying to set the state to this however results in an error. I'm currently trying to teach myself react, so I'm not as familiar with my options and have been struggling to find a solution.
I feel like I might be missing something obvious here. I also likely have the option to do this in the backend in spring boot/java and then return that.
data.map(([id, quantity]) => <Bar label={id} quantity={quantity} />