Traversing arrays in javascript

Hello Experts,

I have the following code:

		var myarr = new Array();
		myarr[10] = 10;
		myarr[5] = 50;
		myarr[17] = 70;

		for(var i in myarr)
		{
			document.write("<BR>"+i);
		}

Open in new window


How can I traverse the array so the results is:

5
10
17

Thanks!
jagkuAsked:
Who is Participating?
 
leakim971Connect With a Mentor PluritechnicianCommented:
		for(var i=0;i<myarr.length;i++)
		{
			if(myarr[i]!=null) document.write("<BR>"+i);
		}

Open in new window

0
 
jagkuAuthor Commented:
Ahhh, I tried that - but thought there might be something more jazzier!

As usual, thank you!!!
0
All Courses

From novice to tech pro — start learning today.