Well, it depends. The length property will return the current size of the array. Since the indexers of an array are zero based, but the length is one based, using the length will always put a new item at the end of the array. For example, consider your loop code:
Array has 0 elements. Length = 0. New item will be added at index 0 (the first item)
Array has 1 element. Length = 1. New item will be added at index 1 (the second item)
If you want to store elements at a specific location in the array, you can do that too (again, using the indexers). If you know your visitor has three friends, this code will ask their names and store them in an array with three elements (number 0, 1 and 2):
Code:
var yourName = "";
var friends = new Array();
yourName = prompt("Enter your name", "")
friends[0] = yourName;
yourName = prompt("Enter your name", "")
friends[1] = yourName;
yourName = prompt("Enter your name", "")
friends[2] = yourName;
var namesList = friends.join("<BR>")
document.write(namesList)
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.