View Full Version : Direct way to read value of an Array variable?

06-13-2003, 06:09 PM
I am passing values to a funtion, and it works fine as long as the variables are individually declared:

var val1="Something"
var val2="Something else"

onclick= return function([var1],[var2])

then the function:
function do_it(invar1, invar2) {
do work invar1 & invar2 }

Everything works fine BUT

I would like to use an array, especially a dense or literal array, but the variables from an array are all var[1] ,var[2], etc.

In that format, the variable values are don't seem to pass to the function with:

onclick= return function([var[1]],[var[2]])

(or 10k other versions I/ve tried. I can 'var[1]' or "var[1]" and pass them as a string, but still need to pull the value from them.

So what I am looking for is a direct conversion, that would be something like this?

var1 = value(var[1])

From what I have seen, it is hard to beleive that JS doesn't provide a direct function / rendition for this! :mad:

06-13-2003, 06:34 PM
this does not work:
onclick= return function(var[1],var[2])

06-13-2003, 07:54 PM
"This Does not Work:"

onclick= return function(var[1],var[2])

neither does this (attempts to use array variable name)

onclick= return function([var[1]],[var[2]])

But this does
onclick= return function([var1],[var2])

As I mentioned the problem here is that If I want to use an array instead of declaring individually, I can't transfer the data (simply).

06-16-2003, 04:53 AM
is your array named var? change it to other name, var is a reserved keyword.

06-24-2003, 12:04 AM
Var is just the sample name, to show placement. Thw question is on syntax for transferring var values from an array?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum