欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

講解JavaScript中for...in語句的使用方法

 更新時間:2015年06月03日 12:21:18   投稿:goldensun  
這篇文章主要介紹了講解JavaScript中for...in語句的使用方法,是JS入門學(xué)習(xí)中的基礎(chǔ)知識,需要的朋友可以參考下

 這里是JavaScript支持的另外一個循環(huán)。它被稱為for...in循環(huán)。這個循環(huán)是用于循環(huán)一個對象的屬性。

因為我們還沒有討論的對象,所以使用這一循環(huán)可能會感覺不太明白。但是,一旦你會對JavaScript對象了解后,那么會發(fā)現(xiàn)這個循環(huán)非常有用。
語法

for (variablename in object){
 statement or block to execute
}

從對象每次迭代一個屬性分配給變量名(variablename),這個循環(huán)持續(xù)到該對象的所有屬性都用盡。
例子:

下面是打印出Web瀏覽器的導(dǎo)航器-Navigator 對象的屬性,如下面的例子:

<script type="text/javascript">
<!--
var aProperty;
document.write("Navigator Object Properties<br /> ");
for (aProperty in navigator)
{
 document.write(aProperty);
 document.write("<br />");
}
document.write("Exiting from the loop!");
//-->
</script>

這將產(chǎn)生以下結(jié)果:

Navigator Object Properties
appCodeName
appName
appMinorVersion
cpuClass
platform
plugins
opsProfile
userProfile
systemLanguage
userLanguage
appVersion
userAgent
onLine
cookieEnabled
mimeTypes
Exiting from the loop! 

相關(guān)文章

最新評論