x
 
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript 数组</h1>
<p>forEach() 方法按顺序为数组中的每个元素调用一次函数。</p>
<p id="demo"></p>
<script>
let text = "";
const fruits = ["apple", "orange", "cherry"];
fruits.forEach(myFunction);
document.getElementById("demo").innerHTML = text;
 
function myFunction(item, index) {
  text += index + ": " + item + "<br>"; 
}
</script>
</body>
</html>