var s=[35,777,664,68,32,-24,-666];
for (a in s){
document.write(s[a])
}
document.write("<br/>--------------------------<br/>")
for (a of s){
document.write(a)
}
document.write("<br/>--------------------------<br/>")
s.forEach(function (value, index, array){
document.write(value)
})
document.write("<br/>--------------------------<br/>")
var i=0
while (s[i]) {
document.write(s[i])
i++;
}
本文通过一个简单的JavaScript示例展示了不同的数组遍历方法,包括for循环、Array.prototype.forEach及while循环等,有助于理解JavaScript中处理数组的基本技巧。
961

被折叠的 条评论
为什么被折叠?



