forEach()
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>forEach</title> </head> <body> <p>点击按钮将数组中的所有值乘以特定数字。</p> <p>乘以: <input type="number" id="multiplyWith" value="10"></p> <button onclick="numbers.forEach(myFunction)">点我</button> <p>计算后的值: <span id="demo"></span></p> <script> var numbers = [65, 44, 12, 4]; function myFunction(item,index,arr) { arr[index] = item * document.getElementById("multiplyWith").value; demo.innerHTML = numbers; } </script> </body>