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 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing Dyanmic Array values to Javascript Function

    I want to pass dynamic array values to java script function.how its possible. explain with some code.........

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,454
    Thanks
    76
    Thanked 4,373 Times in 4,338 Posts
    ??? same way you pass any array.

    The question is: Where is the "dynamic array" coming from? What are the elements of the array? Is the array homogeneous or heterogeneous? Is it an associative array or a numbered array?

    But, really, all those questions would apply to a static array as well as a dynamic one.

    Is this homework?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    ??? same way you pass any array.

    The question is: Where is the "dynamic array" coming from? What are the elements of the array? Is the array homogeneous or heterogeneous? Is it an associative array or a numbered array?

    But, really, all those questions would apply to a static array as well as a dynamic one.

    Is this homework?

    how to pass static array that i dont know can you tell me with code....

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,454
    Thanks
    76
    Thanked 4,373 Times in 4,338 Posts
    Code:
    var names = [ "Adam", "Bob", "Cherry", "Dana" ];
    var cities = ["Atlanta", "Boston", "Chicago" ];
    
    function reverseArray( ar )
    {
        var reverse = [];
        for ( var ix = ar.length-1; ix >= 0; --ix )
        {
            reverse.push( ar[ix] );
        }
        return reverse;
    }
    
    alert( names );
    alert( reverseArray(names) );
    alert( cities );
    alert( reverseArray(cities) );
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,335
    Thanks
    11
    Thanked 588 Times in 569 Posts
    Quote Originally Posted by Old Pedant View Post
    Code:
    var names = [ "Adam", "Bob", "Cherry", "Dana" ];
    var cities = ["Atlanta", "Boston", "Chicago" ];
    
    function reverseArray( ar )
    {
        var reverse = [];
        for ( var ix = ar.length-1; ix >= 0; --ix )
        {
            reverse.push( ar[ix] );
        }
        return reverse;
    }
    
    alert( names );
    alert( reverseArray(names) );
    alert( cities );
    alert( reverseArray(cities) );

    what's with that function?

    Code:
    function reverseArray( ar ){
         return ar.concat().reverse();
    }
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,454
    Thanks
    76
    Thanked 4,373 Times in 4,338 Posts
    Yes, yes, I know. But he wanted a DEMONSTRATION of accessing an array, so I wanted to show visiting all the elements. Reversing was the simplest thing I could think of. <grin/>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,335
    Thanks
    11
    Thanked 588 Times in 569 Posts
    Quote Originally Posted by Old Pedant View Post
    Yes, yes, I know. But he wanted a DEMONSTRATION of accessing an array, so I wanted to show visiting all the elements. Reversing was the simplest thing I could think of. <grin/>
    touchè; i just worry about noobs copy and pasting this wonderful working reverse function into some page i have to wait for...
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%


  •  

    Posting Permissions

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