I have multiple arrays within an object that I would like to iterate through using numeric values. This is necessary in order to assign them to different slots in an accordion loop. The JSON file containing the data looks similar to this (Pokemon used as an example):
{
"Pokemon": {
"FirePokemon": [
{
"name": "Vulpix",
"speed": "10",
"attack": "10",
"defence": "10"
},
{
"name": "Charmander",
"speed": "10",
"attack": "10",
"defence": "10"
}
],
"WaterPokemon": [
{
"name": "Squirtle",
"speed": "10",
"attack": "10",
"defence": "10"
},
{
"name": "Wartortle",
"speed": "10",
"attack": "10",
"defence": "10"
}
],
"GrassPokemon": [
{
"name": "Bulbasaur",
"speed": "10",
"attack": "10",
"defence": "10"
},
{
"name": "Oddish",
"speed": "10",
"attack": "10",
"defence": "10"
}
]
}
}
The objective is to reference the data as follows:
function SetJsonDataToAccordion() {
for (var i = 0; i < Object.keys(pokemondata).length; i++) {
CreateAccordionContent(pokemondata[i], ".accordtitle"+i);
}
}
In this case, pokemondata represents the variable containing all the JSON data. While pokemondata[i] doesn't function correctly, the goal is to cycle through the various types of Pokemon in the loop without explicitly naming the arrays. It works when directly specifying a specific array like 'pokemondata.FirePokemon', but the requirement is to iterate through them. Is there a method to achieve this by iterating through the arrays within an object?