Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Email:

Building a Javascript Array

By Darren W. Hedlund
2005-03-29


Building a Javascript Array

Here are the basics of how to make a simple javascript array for your HTML page.

To get you started, first you have to call the scripting method you are going to use. In this case we will call javascripting method.
<script language="javascript">

Next, we call up the varible array and declare the number of entries in that varible.
test1 = new Array(5)

Now we list the entries into that varible test1 and is limited to 5.
test1[0] = "this is entry one -";
test1[1] = "this is entry two -";
test1[2] = "this is entry three -";
test1[3] = "this is entry four -";
test1[4] = "this is entry five -";

Now to display this in the document.
document.write(test1[0],test1[1],test1[2],test1[3],test1[4],test1[5]);

Now, we close the script.
</script>


Complete code:
<html>
<head>
</head>
<body>
<script language="javascript">

test1 = new Array(5)
test1[0] = "this is entry one -";
test1[1] = "this is entry two -";
test1[2] = "this is entry three -";
test1[3] = "this is entry four -";
test1[4] = "this is entry five -";
document.write(test1[0],test1[1],test1[2],test1[3],test1[4],test1[5]);

</script>

</body>
</html>


Tutorial Pages:
» Building a Javascript Array


 | Bookmark
Related Tutorials:
» JavaScript Debugging Techniques with Firebug
» Striped Tables Using JavaScript
» Opening PDFs in a New Window with JavaScript
» Essential Javascript -- A Javascript Tutorial
» Submit Forms Conditionally using JavaScript
» How to Setup a Randomising Function