Javascript Basics Tutorial
JavaScript Objects
JavaScript Advanced
JavaScript Useful Resources
Selected Reading
- Javascript - Page Printing
- Javascript - Void Keyword
- Javascript - Dialog Boxes
- Javascript - Page Redirect
- Javascript - Cookies
- Javascript - Events
- Javascript - Functions
- Javascript - Loop Control
- Javascript - For...in
- Javascript - For Loop
- Javascript - While Loop
- Javascript - Switch Case
- Javascript - If...Else
- Javascript - Operators
- Javascript - Variables
- Javascript - Placement
- Javascript - Enabling
- Javascript - Syntax
- Javascript - Overview
- Javascript - Home
JavaScript Objects
- Javascript - HTML DOM
- Javascript - RegExp
- Javascript - Math
- Javascript - Date
- Javascript - Arrays
- Javascript - Strings
- Javascript - Boolean
- Javascript - Number
- Javascript - Objects
JavaScript Advanced
- Javascript - Browsers
- Javascript - Image Map
- Javascript - Debugging
- Javascript - Multimedia
- Javascript - Animation
- Javascript - Validations
- Javascript - Error Handling
JavaScript Useful Resources
- Javascript - Resources
- Javascript - Functions
- Javascript - Quick Guide
- Javascript - Questions And Answers
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Javascript - For...in
JavaScript for...in loop
The for...in loop is used to loop through an object s properties. As we have not discussed Objects yet, you may not feel comfortable with this loop. But once you understand how objects behave in JavaScript, you will find this loop very useful.
Syntax
The syntax of ‘for..in’ loop is −for (variablename in object) { statement or block to execute }
In each iteration, one property from object is assigned to variablename and this loop continues till all the properties of the object are exhausted.
Example
Try the following example to implement ‘for-in’ loop. It prints the web browser’s Navigator object.
<html> <body> <script type = "text/javascript"> <!-- var aProperty; document.write("Navigator Object Properties<br /> "); for (aProperty in navigator) { document.write(aProperty); document.write("<br />"); } document.write ("Exiting from the loop!"); //--> </script> <p>Set the variable to different object and then try...</p> </body> </html>
Output
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...Advertisements