删除数组项目

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h1>JSON 数组</h1>
  6.  
  7. <p>如何删除数组的属性。</p>
  8.  
  9. <p id="demo"></p>
  10.  
  11. <script>
  12. var myObj, i, x = "";
  13. myObj = {
  14. "name":"Bill Gates",
  15. "age":62,
  16. "cars": ["Porsche","BMW","Volvo"]
  17. }
  18. delete myObj.cars[2];
  19.  
  20. for (i in myObj.cars) {
  21. x += myObj.cars[i] + "<br>";
  22. }
  23. document.getElementById("demo").innerHTML = x;
  24. </script>
  25.  
  26. </body>
  27. </html>