469,349 Members | 1,497 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,349 developers. It's quick & easy.

Array Referencing

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
6 1161
gits
5,390 Expert Mod 4TB
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
16,027 Expert Mod 8TB
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
5,390 Expert Mod 4TB
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
thank you guys for your help :)
Aug 3 '08 #5
acoder
16,027 Expert Mod 8TB
You're welcome. So which one did you choose? ;)
Aug 4 '08 #6
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.

Similar topics

4 posts views Thread by Bosconian | last post: by
5 posts views Thread by Denis Perelyubskiy | last post: by
5 posts views Thread by Paulers | last post: by
4 posts views Thread by Armand | last post: by
7 posts views Thread by heddy | last post: by
2 posts views Thread by JJA | last post: by
10 posts views Thread by =?Utf-8?B?R2Vvcmdl?= | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.