Solved

Traversing arrays in javascript

Posted on 2012-03-12
2
222 Views
Last Modified: 2012-03-12
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!
0
Comment
Question by:jagku
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 37710341
		for(var i=0;i<myarr.length;i++)
		{
			if(myarr[i]!=null) document.write("<BR>"+i);
		}

Open in new window

0
 

Author Closing Comment

by:jagku
ID: 37710376
Ahhh, I tried that - but thought there might be something more jazzier!

As usual, thank you!!!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now