We help IT Professionals succeed at work.

Traversing arrays in javascript

jagku
jagku asked
on
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!
Comment
Watch Question

Multitechnician
SILVER EXPERT
Distinguished Expert 2019
Commented:
		for(var i=0;i<myarr.length;i++)
		{
			if(myarr[i]!=null) document.write("<BR>"+i);
		}

Open in new window

Author

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

As usual, thank you!!!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.