For ... loop in JavaScript

The for ... in loop is used to iterate over the properties of an object. When we haven't discussed the object yet, you may not feel comfortable with this loop. But once you understand how objects work in JavaScript, you will find this loop very useful.

The for . in loop is used to iterate over the properties of an object. When we haven't discussed the object yet, you may not feel comfortable with this loop. But once you understand how objects work in JavaScript, you will find this loop very useful.

Syntax

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

In each iteration, an attribute from the object - the object is assigned to variablename - the variable name and this loop continue until all properties of the object are gone.

For example

You try the following example of a for . in loop. It prints the Navigator object of the web browser.

  type = "text/javascript" >  
 Set the variable to different object and then try. 

Result:

 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!
Đặt biến vào đối tượng khác và Then thử .

 

According to Tutorialspoint

Previous article: For loop in JavaScript

Next lesson: Loop control in JavaScript

Update 25 May 2019
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile