I am trying to create multidimensional arrays that will contain 6 JSON responses. I turned to others for help: multidimensional array in angular
but when I test my console log for a multidimensional array, I get the output "Stat array: undefined", calling only this index of the whole array returns [object Object].
$scope.pokeArray = new Array(11);
$http.get("http://pokeapi.co/api/v2/pokemon/"+searchedName +".json")
.success(function (response)
{
$scope.pokeArray[0] = response.forms[0].name;
$scope.pokeArray[1] = response.id;
$scope.pokeArray[2] = response.height;
$scope.pokeArray[3] = response.sprites.front_default;
$scope.pokeArray[4] = response.sprites.front_shiny;
$scope.pokeArray[5] = response.stats[1].base_stat;
$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);
}
);
}
As you can see, my first 5 arrays contain direct answers, and this works great, I tested it using my console logs, and I used the information in my html view.
"Stat array: undefined". , theres -, mutlidemensional, , , , [6] [0], , ? .
- , JSON, , . .