删除数组中最后一个元素 - pop()

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h1>JavaScript 数组方法</h1>
  6.  
  7. <h2>pop()</h2>
  8.  
  9. <p>pop() 方法从数组中删除最后一个元素。</p>
  10.  
  11. <p id="demo1"></p>
  12. <p id="demo2"></p>
  13.  
  14. <script>
  15. var fruits = ["Banana", "Orange", "Apple", "Mango"];
  16. document.getElementById("demo1").innerHTML = fruits;
  17. fruits.pop();
  18. document.getElementById("demo2").innerHTML = fruits;
  19. </script>
  20.  
  21. </body>
  22. </html>