【发布时间】:2021-09-07 13:37:13
【问题描述】:
const arr=[1,2,3,4,5];
arr.forEach(function(val){
console.log(val);
})
| Output |
|---|
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
const arr=[1,2,3,4,5];
arr.forEach(function(val){
document.getElementById("demo").innerHTML=val;
})
| Output |
|---|
| 5 |
我的问题是为什么即使在使用相同的代码行后我得到不同的输出。
【问题讨论】:
-
因为循环做完全不同的事情。为什么您认为登录到控制台与更新某些元素的 HTML 相同?
标签: javascript getelementbyid console.log