Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Accessing individual elements in an array-please help!


  • Please log in to reply

#1
rps2

rps2

    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>');
else
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

Advertisements







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