无涯教程-Javascript - For...in循环语句

for ... in 循环用于循环访问对象的属性,由于无涯教程尚未讨论Objects对象,您就会发现此循环非常有用。

“ for...in”循环的语法为:
for (variablename in object) {
   statement or block to execute
}

在每次迭代中,将 object对象中的一个属性分配给 variablename 变量,此循环一直进行到对象的所有属性。

请尝试以下示例来实现" for-in"循环,它将打印网络浏览器的 Navigator 对象。


         
       type = "text/javascript">
         
            
      

Set the variable to different object and then try...

运行上面代码输出

NavigatorObjectProperties 
serviceWorker 
webkitPersistentStorage 
webkitTemporaryStorage 
geolocation 
doNotTrack 
onLine 
languages 
language 
userAgent 
product 
platform 
appVersion 
appName 
appCodeName 
hardwareConcurrency 
maxTouchPoints 
vendorSub 
vendor 
productSub 
cookieEnabled 
mimeTypes 
plugins 
javaEnabled 
getStorageUpdates 
getGamepads 
webkitGetUserMedia 
vibrate 
getBattery 
sendBeacon 
registerProtocolHandler 
unregisterProtocolHandler 
Exiting from the loop!
Set the variable to different object and then try...

参考链接

https://www.learnfk.com/javascript/javascript-forin-loop.html

你可能感兴趣的:(无涯教程,javascript)