更改数组元素

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h1>JavaScript 数组</h1>
  6.  
  7. <p>使用数字索引(从 0 开始)访问 JavaScript 数组元素。</p>
  8.  
  9. <p id="demo"></p>
  10.  
  11. <script>
  12. var cars = ["Audi", "BMW", "porsche"];
  13. cars[0] = "Volvo";
  14. document.getElementById("demo").innerHTML = cars;
  15. </script>
  16.  
  17. </body>
  18. </html>