How To Make Javascript Arrays

RegisterLogin
How To Make Javascript Arrays
Post Description: Showing You Making Arrays Using Javascript To Make A Simple Javascript Array And Then Display The Centent Of Each Element On The Webpage
Tags: How, To, Make, Javascript, Arrays
This Post Was Posted On Dec 27, 2009 By Webune Support #2959
so lets say you want to create an array in javascript and then be able to display each value for each array element, its very simple, there are many ways to create arrays in javascript, here are some examples:

regular array example (add an optional integer argument to control array's size)
var Colors=new Array();
Colors[0]="red";
Colors[1]="green";
Colors[2]="blue";

this is a condensed array:
JAVASCRIPT CODE:
var Colors=new Array("red","gree","blue");


example literal array
JAVASCRIPT CODE:
var Colors=["red","green","blue"];


now try it yourself, we put together a sample code:
JAVASCRIPT CODE:
<script type="text/javascript">


var Colors=new Array(); // regular array (add an optional integer
Colors[0]="red"; // argument to control array's size)
Colors[1]="green";
Colors[2]="blue";

document.write(Colors[0]);
</script>


try it,,

next step: the best way to display all the elements of an array if you want to list them, its to use a loop learn how on our next tutorial:

How To Make Array In Javascript
Leave Your Comments
plater
#3340 1
can you explain condensed array vs literal array javascript

plez
Jan 27, 2010 Reply Report abuse
dondoe
#3114 2
you can learn more here:

http://www.java2s.com/Code/JavaScript/Form-Control/UsingtheformelementsArray.htm
Dec 27, 2009 Reply Report abuse
©2012 Webune Forums - Tue Dec 18, 2012 4:03 pm
Powered by: Webune Forums V3