萬盛學電腦網

 萬盛學電腦網 >> 腳本專題 >> javascript >> Javascript中For In語句用法實例

Javascript中For In語句用法實例

   本文實例講述了Javascript中For In語句用法。分享給大家供大家參考。具體如下:

  ?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>For In 語句</title> <script type="text/javascript"> function Student(name, age) { this.name = name; this.age = age; } var stu = new Student("內馬爾", 20); //遍歷對象 for (var s in stu) { alert(s + ":" + stu[s]); } //遍歷數組 var myArr = [1, 3, 5, 7, 9]; for (var i in myArr) { alert(i + ":" + myArr[i]); } </script> </head> <body> </body> </html>

  希望本文所述對大家的javascript程序設計有所幫助。

copyright © 萬盛學電腦網 all rights reserved