473,396 Members | 1,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 1349
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

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

Similar topics

6
by: Krackers | last post by:
How do you write a function which returns a reference to an array. I can only get a function to return a copy of the array itself. I've had a look at some other threads in this group an the return...
4
by: Bosconian | last post by:
I've been researching this for hours and can't seem to find the right syntax. I need to retrieve a value of an array by referencing the element using a string variable. For example: $data...
5
by: Denis Perelyubskiy | last post by:
Hello, I need to make an array of elements accross forms. My javascript skills, as evident from this question, are rather rudimentary. I tried to make an associative array and index it with...
35
by: VK | last post by:
Whatever you wanted to know about it but always were affraid to ask. <http://www.geocities.com/schools_ring/ArrayAndHash.html>
5
by: Varangian | last post by:
ImageButton ship; ship = new ImageButton; for (int i=0; i<5; i++) { ship.ImageUrl = pathofImage; ship.ID = "ShipNo" + i.ToString(); ship.Click += new...
5
by: Paulers | last post by:
Hello all, I have a string array with duplicate elements. I need to create a new string array containing only the unique elements. Is there an easy way to do this? I have tried looping through...
4
by: Armand | last post by:
Hi Guys, I have a set of array that I would like to clear and empty out. Since I am using "Array" not "ArrayList", I have been struggling in finding the solution which is a simple prob for those...
7
by: heddy | last post by:
I have an array of objects. When I use Array.Resize<T>(ref Object,int Newsize); and the newsize is smaller then what the array was previously, are the resources allocated to the objects that are...
2
by: JJA | last post by:
I'm looking at some code I do not understand: var icons = new Array(); icons = new GIcon(); icons.image = "somefilename.png"; I read this as an array of icons is being built. An element of...
10
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, There is error message when executing my program, Unhandled exception at 0x00411a49 in test_entern.exe: 0xC0000005: Access violation reading location 0x00000002. It is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.