My goal is to construct a multidimensional array capable of storing 6 JSON responses. To seek guidance, I have consulted other resources such as this thread on multidimensional arrays in Angular.
However, upon testing my console log for the multidimensional array, I am met with the output "Stat array: undefined". Simply calling an index of the entire array returns [object Object].
$scope.pokeArray = new Array(11);
$http.get("http://pokeapi.co/api/v2/pokemon/"+searchedName +".json")
.success(function (response)
{
//Get first form FORMS array, assign name
$scope.pokeArray[0] = response.forms[0].name;
//13 ID
$scope.pokeArray[1] = response.id;
//10 Height
$scope.pokeArray[2] = response.height;
//7 Sprites
$scope.pokeArray[3] = response.sprites.front_default;
$scope.pokeArray[4] = response.sprites.front_shiny;
//3 Stats 5-11
//Speed
$scope.pokeArray[5] = response.stats[1].base_stat;
//Index 6 = Array of 6
$scope.pokeArray[6] = [
{
speed : response.stats[0].base_stat,
spDefense: response.stats[1].base_stat,
spAttack : response.stats[2].base_stat,
defense : response.stats[3].base_stat,
attack : response.stats[4].base_stat,
hp : response.stats[5].base_stat
}];
console.log("Name: " + response.forms[0].name);
console.log("Height: "+ response.height);
console.log("ID: " + response.id);
console.log("Array: " + $scope.pokeArray);
console.log("speed: " + response.stats[1].base_stat);
console.log("Stat array: " + $scope.pokeArray[6].speed);
}
);
}
The initial 5 arrays contain the direct responses and function as intended – verified through console logs and HTML view utilization.
At present, the final console log displays "Stat array: undefined". I ponder if there's an alternate method to structure my responses within the multidimensional array; for instance, attempting to access speed using [6][0] prompts an error.
If anyone could shed light on whether it's the array setup or JSON processing that's inducing this issue, I would greatly appreciate the insight. Thank you.