本文實例講述了Javascript中For In語句用法。分享給大家供大家參考。具體如下:
<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程序設計有所幫助。