Forbrukslånkalkulator | Sähkövertailu | Nytt Kredittkort | Strøm | Billig Husalarm | Forsikring Sammenligning | Mobilselskaper i Norge | Handle Godteri på Nett
JavaScript programming

for-in-loop java script

Written by Tusher

JavaScript is used for-in loop and the array elements in the object’s properties. Syntax for-in loop is for (variable name in object) {statements}.

The above example var oproperty; The variables must be declared for a for-in loop.

for (oproperty in history) reveals that the history of each property of the object to be accepted as an alternate oproperty variables.

document.write (oproperty); Oproperty the browser to display the values of variables have been issued.

var i; A second for the for-in loop variables must be declared.

var name = new Array (); Through an array has been created, which will be adopted as the variable name.

name [0] = “Karim”; name [1] = “Rahim”; name [2] = “Manik”; name [3] = “Abdullah”; The Array material has been published.

for (i in name) revealed that the name of each element of the array as the variable i will be taken periodically.

document.write (name [i] + “<br />”); The element of the array of variable values as I have been asked to display the browser.

Practice Project:

body{background: #FFC;

<script type = “text/javascript”>
document.write(“<h2>Example of for-in loop </h2>”);
var oproperty;
document.write(“<h2>History Object Properties </h2> “);
for (oproperty in history)
document.write(“<br />”);
<script type=”text/javascript”>
document.write(“<h2>for-in loop in array </h2> “);
var i;
var name = new Array();
name[0] = “Karim”;
name[1] = “Rahim”;
name[2] = “Manik”;
name[3] = “Abdullah”;
for (i in name)
document.write(name[i] + “<br />”);


Notepad: to open a file type from the menu at the top of layer code by clicking on the Save as File name: index.html, Save as type: All files, save and open the index.html file with the Mozilla Firefox look like the image shown below.

Example of for-in loop

History Object Properties


for-in loop in array

About the author