JavaScript :: for…循环中
在 为...在 循环通过一个对象的属性用于循环。由于我们尚未讨论对象,因此您可能不喜欢此循环。但是一旦了解了对象在JavaScript中的行为,您就会发现此循环非常有用。
语法
for..in循环的语法是-
for (variablename in object) {
statement or block to execute
}在每次迭代中,将来自对象的一个属性 分配给 变量名, 并且此循环一直进行到对象的所有属性用尽为止。
例子
尝试以下示例实现“for-in”循环。它打印Web浏览器的 Navigator 对象。
Set the variable to different object and then try...
输出
Navigator Object Properties 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...
热门推荐
10 广西考试祝福语结婚简短
11 猪年祝福语简短小孩
12 元旦祝福语送长辈简短
13 恭喜二宝祝福语简短
14 祝福语暖心话简短
15 国庆中秋祝福语简短兄弟
16 朋友订婚的祝福语简短
17 送弟弟中秋祝福语简短
18 爱生日祝福语简短独特