Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works

Accessing individual elements in an array-please help!

  • Please log in to reply



    New Member

  • Member
  • Pip
  • 3 posts
If I wanted to excute one statement if an element in an array was equal to one thing but excute a different statement if the element was equal to something else how do I write code to access these individual arrays?

So if I had an array like this for example:

my_Array = ['a','a','a','a','42','54','a','a,'2','a','69']

if an element in the array was equal to 'a'
document.write('No number' + '<BR>');
if an element in the array was equal to a number
multiply this number by 2.

would I need to use a for loop:
for ( x in my_Array)

but then this is wear i'm stuck what do I equal it to in an if statement??
if (my_Array[x] == ???

cos if I write if (my_Array[x] == a)
it obviously doesen't recognize 'a'
So how do write out an individual element in an Array??

Am i on the right tracks here?
Any help would be great as I'm fairly new tothis as you can probably tell.
  • 0


Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP