referencing arrays

They have: 5,633 posts

Joined: Jan 1970

I was wondering if it is possible to reference an array w/ an array. And if so, how. This is what I have been trying, but it doesn't seem to be working:

array1[array2[x]]

Any help would be greatly appreciated.

Thanks.

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Hi,

Based upon the little you wrote, I'm presuming you have 2 arrays (and not an array within an array)
If that is true, then the following:

someVar = array1[array2[x]];
eval(array1[array2[x]]);

should work as long as array2[x] is returning an integer within the index range of array1. (if they are selection lists, you must also remember that it is the 'value' of the array being returned.)

If you are dealing with arrays within arrays, see the "Arguments Object" and "Rolodex" scripts at my site for examples of accessing data.

Vinny GrassBlade: cut&paste javascript

Where the world once stood
the blades of grass cut me still

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.