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.

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

5 ★ | 1 Vote

May be interested

  • What is JavaScript? Can the Internet exist without JavaScript?What is JavaScript?  Can the Internet exist without JavaScript?
    not everyone knows what javascript is and how it works. the long and fascinating development history of javascript as well as what we can do with javascript is still unknown.
  • How to Fix Boot Loop Problems in WindowsHow to Fix Boot Loop Problems in Windows
    after starting your windows device, you may sometimes experience an infinite boot loop issue (also known as an 'infinite boot loop' error).
  • While loop in PythonWhile loop in Python
    what does the while loop in python do? what is the syntax and how to use while loop? those are the content we will approach in this python lesson.
  • What is Currying in Javascript? How to use Currying in JavaScriptWhat is Currying in Javascript? How to use Currying in JavaScript
    the currying feature in javascript can help you keep your code tidy and give you a new way of seeing how functions work. currying is ideal when you want to break complex logic into smaller, manageable, and self-contained pieces of code.
  • What is Loop mail?What is Loop mail?
    what is loop mail? to help you with this question, the following article will help you find out what loop mail is.
  • Things to know about 'this' in JavaScriptThings to know about 'this' in JavaScript
    are you having trouble understanding the keyword 'this' in javascript ? then please read what you need to know about 'this' in javascript below.
  • Udemy's top 5 JavaScript coursesUdemy's top 5 JavaScript courses
    a programming language that runs on any computer in the world. a language does not need any special software to run. a language ranked among the top in the world.
  • Why Microsoft Loop Can't Compare to NotionWhy Microsoft Loop Can't Compare to Notion
    many people have been using notion for brainstorming for years, so it's interesting to see if loop can replace it as they move deeper into the microsoft ecosystem.
  • Top site with many good JavaScript exercises to practiceTop site with many good JavaScript exercises to practice
    many people, after taking javascript courses and being equipped with some knowledge of the language they pursue, are eager to improve and cultivate these learned skills. so this article will give you a list of the top 3 websites to actually make javascript.
  • What is JavaScript?What is JavaScript?
    javascript is a programming language of html and web. it is lightweight and most commonly used as part of web pages, but their implementation allows client-side scripts to interact with users and create dynamic websites. it is an interpreted programming language with object-oriented capabilities.