Schmeck
asked on
Calling a specific Javascript array
This is probably an easy questions, but I'm a bit of a JavaScript newbie,
I have created and filled a bunch of arrays using an ASP loop. The arrays were created looking like this
var amount1 = new Array(250, 0)
var amount2 = new Array(500, 0)
var amount3 = new Array(0, 250)
...and so on
So, I want to call a specific array, based on a variable passed into the function (intSel). This variable will be used to select the correct array by providing the number after "amount". How do I concatenate this thing to return the values contained in the array itself, instead of just a string.
Right now I have a line that says:
document.getElementById('D ebit0').va lue = "amount" + intSel + "[0]";
But of course that doesn't work and returns "amount2[0]", for example.
I want it to return 500.
Thanks for your help!
Dan
I have created and filled a bunch of arrays using an ASP loop. The arrays were created looking like this
var amount1 = new Array(250, 0)
var amount2 = new Array(500, 0)
var amount3 = new Array(0, 250)
...and so on
So, I want to call a specific array, based on a variable passed into the function (intSel). This variable will be used to select the correct array by providing the number after "amount". How do I concatenate this thing to return the values contained in the array itself, instead of just a string.
Right now I have a line that says:
document.getElementById('D
But of course that doesn't work and returns "amount2[0]", for example.
I want it to return 500.
Thanks for your help!
Dan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Zontar...that's what I was looking for!
Cool. No worries, Schmeck.
Technically, JavaScript doesn't support multi-dimensional arrays, but array elements can be of any type -- including arrays -- which makes that sort of a moot point. ;)
(Arrays of objects/associative arrays can also be handy at times when you need to roll your own data structures in a hurry.)
Technically, JavaScript doesn't support multi-dimensional arrays, but array elements can be of any type -- including arrays -- which makes that sort of a moot point. ;)
(Arrays of objects/associative arrays can also be handy at times when you need to roll your own data structures in a hurry.)
document.getElementById('D
you could use
document.getElementById('D
prodvided that amount1, amount2, etc. are defined as global variables and not as local to a function.