Helping ordinary people create extraordinary websites!

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
 1 Votes

You might also want to check these out:


Leave a Comment on "Building a Javascript Array"
You must be logged in to post a comment.

Link to This Tutorial Page!


GET OUR NEWSLETTERS