Question:
I want to showing data like this:
I’ve trying some method, but still get confused and showing not what I want. By the code below:
It’s only showing like this :
I have JSON format like this:
Answer:
Given the format of your data where the name/count are in separate arrays, you can use a basic
for
loop to get the index for each disaster, to get the corresponding name/count based on that index
This
assumes there’s the same number of disaster names as counts and that the associated values are in the same order – eg count[0] is for forest fires.
As you can change the format, you could make it more object-like, eg an array of:
then the js will be closer to your initial attempt as you don’t need to loop the index and can use a .forEach() or .map()
If you have better answer, please add a comment about this, thank you!