Share on Google+Share on Google+
JavaScript Array
Posted on: November 6, 2009 at 12:00 AM
Advertisement
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
Advertisement

Related Tags for JavaScript Array:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 6, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com