使用 For…In 声明来遍历数组内的元素

  1. <html>
  2. <body>
  3. <script type="text/javascript">
  4. var x
  5. var mycars = new Array()
  6. mycars[0] = "宝马"
  7. mycars[1] = "奔驰"
  8. mycars[2] = "宾利"
  9.  
  10. for (x in mycars)
  11. {
  12. document.write(mycars[x] + "<br />")
  13. }
  14. </script>
  15. </body>
  16. </html>