访问数组值

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h1>JSON 数组</h1>
  6.  
  7. <p>访问 JSON 对象的数组值。</p>
  8.  
  9. <p id="demo"></p>
  10.  
  11. <script>
  12. var myObj, x;
  13. myObj = {
  14. "name":"Bill Gates",
  15. "age":62,
  16. "cars":[ "Porsche", "BMW", "Volvo" ]
  17. };
  18. x = myObj.cars[0];
  19. document.getElementById("demo").innerHTML = x;
  20. </script>
  21.  
  22. </body>
  23. </html>