I'm trying to use a variable for skillName which represents 'Tackle' and i dont want to use userBattlePokemon[0].skills.Tackle
because i want my code to be more dynamic for different skills from different objects.
But skillName currently represents a string, which means the enemyBattlePokemon[0].health
became NaN
.
For this instance, is there any way to write it so that skillName
returns Tackle
which is not a string and can be used in the assignment?
userBattlePokemon = [{
skills: {
Tackle: 5,
LeechSeed: 10
}
}];
enemyBattlePokemon = [{
health: 100
}];
let skillName = userBattlePokemon[0].skills[0]
enemyBattlePokemon[0].health = enemyBattlePokemon[0].health - userBattlePokemon[0].skills[0].skillName