我只是想知道你是否可以使用变量读取JSON数组。我的代码:
var runningtotal = 0;
var dollartoletter = {
"a": 1,
"b": 2,
"c": 3,
"d": 4,
"e": 5,
"f": 6,
"g": 7,
"h": 8,
"i": 9,
"j": 10,
"k": 11,
"l": 12,
"m": 13,
"n": 14,
"o": 15,
"p": 16,
"q": 17,
"r": 18,
"s": 19,
"t": 20,
"u": 21,
"v": 22,
"w": 23,
"x": 24,
"y": 25,
"z": 26
};
for (var i = 0; i < word.length; i++) {
var currentChar = word.charAt(i);
console.log(currentChar);
var numforcurrentChar = dollartoletter.currentChar;
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^this is what produces errors
console.log(numforcurrentChar);
var runningtotal = runningtotal + numforcurrentChar;
console.log(runningtotal);
}
如果无法做到这一点,那也没关系。我宁愿不使用jQuery,但如果需要的话,我可以很好地实现它。