所以我现在正试图做标题状态,我有两个数组,
var weapon = ["Stick", "Dagger", "Shortsword", "Longsword", "Magical Sword", "Chunchunmaru"];
和
var weaponAverageDamage = [0, 3, 6, 9, 12, 15];
我想拥有它,无论具体的索引“武器”是什么,武器平台损坏都是一样的。例如,程序中武器[1]出现的任何实例,如果正在计算怪物的健康状况,那么也会访问weaponAverageDamage [1]。
答案 0 :(得分:2)
考虑到数组weaponAverageDamage
根据weapon
数组中每个武器的相应值排序,我们可以这样做:
var weapon = ["Stick", "Dagger", "Shortsword", "Longsword", "Magical Sword", "Chunchunmaru"];
var weaponAverageDamage = [0, 3, 6, 9, 12, 15];
var weaponIndex = weapon.indexOf(weapon[2])
var AvgDamage = weaponAverageDamage[weaponIndex]; //required value