By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,818 Members | 2,089 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,818 IT Pros & Developers. It's quick & easy.

Array Referencing

P: 57
Hi all,

I have the following array with which I need to reference to the second item in every array and write it out onto the page, how can this be done?

Expand|Select|Wrap|Line Numbers
  1. var arr = new Array();
  2. arr[0] = 'images/001.jpg','Image 1 Description SECOND ITEM';
  3. arr[1] = 'images/002.jpg','Image 2 Description SECOND ITEM';
  4.  
Thanks in advance.
Aug 3 '08 #1
Share this Question
Share on Google+
6 Replies


gits
Expert Mod 5K+
P: 5,344
you may use the following example ... the object in the array-elements makes it easy to refer:

Expand|Select|Wrap|Line Numbers
  1. arr[0] = { 
  2.     src: 'images/001.jpg',
  3.     dsc: 'Image 1 Description SECOND ITEM' 
  4. };
  5.  
  6. // now refer with the following:
  7.  
  8. arr[0].src // your source
  9. arr[0].dsc // your description
  10.  
kind regards
Aug 3 '08 #2

acoder
Expert Mod 15k+
P: 16,027
Define each one like this
Expand|Select|Wrap|Line Numbers
  1. var arr = [];
  2. arr[0] = ['images/001.jpg','Image 1 Description SECOND ITEM'];
  3. arr[1] = ['images/002.jpg','Image 2 Description SECOND ITEM'];
  4.  
instead, then you can refer to the second item with arr[0][1], arr[1][1], etc.

Edit: obs, too late and after a better reply too ;(
Aug 3 '08 #3

gits
Expert Mod 5K+
P: 5,344
yep ... that's the array-solution :) ... where you refer by index ... the object solution allows to refer by name ... now its up to you to choose one :)

kind regards
Aug 3 '08 #4

P: 57
thank you guys for your help :)
Aug 3 '08 #5

acoder
Expert Mod 15k+
P: 16,027
You're welcome. So which one did you choose? ;)
Aug 4 '08 #6

P: 57
I chose your one acoder ;)
Aug 7 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.