Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jun 2003
    Location
    Miami
    Posts
    33
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Direct way to read value of an Array variable?

    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!

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    626
    Thanks
    0
    Thanked 0 Times in 0 Posts
    this does not work:
    onclick= return function(var[1],var[2])

  • #3
    New Coder
    Join Date
    Jun 2003
    Location
    Miami
    Posts
    33
    Thanks
    1
    Thanked 0 Times in 0 Posts
    "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).

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    is your array named var? change it to other name, var is a reserved keyword.

  • #5
    New Coder
    Join Date
    Jun 2003
    Location
    Miami
    Posts
    33
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Var is just the sample name, to show placement. Thw question is on syntax for transferring var values from an array?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •