单击按钮时,我希望列出数组中的结果,例如:John Smith 16、Jack Snow 10 等。
我想使用循环,但是循环中的代码目前不正确,因为当我单击按钮时,我得到的只是:[object Object]。
有人可以提供可能的修复吗?
function begin() {
listresults();
();
}
var results1 = {name:"John Smith", score:16};
var results2 = {name:"Jack Sow", score:10};
var results3 = {name:"Tessa Flip", score:15};
var results = [results1, results2, results3];
function listresults() {
var text = "";
var total = 0;
var i;
for (i in results) {
text += results[i] + "<br>";
}
document.getElementById('message').innerHTML = text;
}
最佳答案
我首先检查两个数组的长度是否相同。然后使用 for 循环进行迭代:
final int timeLength = TIME.length;
if (timeLength != stat.size()) {
//something may not be right
}
for (int i = 0; i < timeLength; i++) {
System.out.println(time[i]+" "+stat.get(i));
}
关于javascript - 使用两个相关数组进行循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44017143/