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 婚前女儿生日祝福语简短