JavaScript Array
Posted on: November 6, 2009 at 12:00 AM
JavaScript Array: In this tutorial you will come to know about array in JavaScript, how to declare, assign values, access values using simple for loop as well as using for..in loop.
JavaScript Array: Almost every language supports array, which is a collection of similar data type, but in JavaScript scripting language it could be or could not be of same. An array could be a collection of similar or dissimilar datatype. Example 1:
<html>

<head>

<title>Write your title here </title>

<script type="text/javascript" >

var x;

var str=new Array();

str[0]="This";

str[1]=1;

str[2]=true;

str[3]=323.233;

document.write("<b>Using simple for loop</b> <br/>");

for(i=0;i<str.length;i++)

{

document.write(str[i]+"<br/>");

}

document.write("<b>Using for...in or for each loop</b> <br/>");

for(x in str)

{

document.write(str[x]+"<br/>");

}

</script>

</head>

</html>

Output:

Using simple for loop This 1 true 323.233 Using for...in or for each loop This 1 true 323.233

Related Tags for JavaScript Array:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.