...

View Full Version : Array Index



treepixie
03-13-2004, 09:13 PM
If the items in an Array Index are numbered 0 - 7 ( dog[0] cat[1] bird[2] pony[3] etc.etc.) is there a way to do a document.write statement that will number them out beginning at 1? ( 1. dog 2. cat 3. bird 4. pony ):confused:

kansel
03-13-2004, 10:47 PM
Simple enough. Just loop through the array and add one to the index when you print it.

var arr_test = new Array("dog","cat","bird","pony","fish","lizard","hamster");
for(var i = 0; i < ar_test.length; i++)
document.write((i+1) + ". " + arr_test[i] + " ");

Tails
03-14-2004, 01:30 AM
A=Array("dog","cat","bird","pony","fox","fish","turtle")
document.write('<ol>')
for(i=0;i<A.length;i++)
{
document.write('<li>'+A[i]+'</li>')
}
document.write('</ol>')



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum