Returning the complete contents of an array to another function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • CES

    Returning the complete contents of an array to another function

    All,

    Sorry for the 101 question but I can't figure out how to return all of the
    contents of an array to another function. I been able to figure out how to
    return individual elements of the array like "return newArray[3]" would
    return the value of value4 in the code below but not the complete array.

    <html>
    <head>
    <title></title>

    <script language="javas cript">
    function tmp(){
    var newArray = new Array("value1", "value2","value 3","value4") ;

    return newArray????;
    }

    function test(){

    document.write( tmp())
    }
    </script>
    </head>
    <body onload="test()" >

    </body>
    </html>


    Any guidance will be appreciated.
    CES


  • Lee

    #2
    Re: Returning the complete contents of an array to another function

    CES said:[color=blue]
    >
    >All,
    >
    >Sorry for the 101 question but I can't figure out how to return all of the
    >contents of an array to another function. I been able to figure out how to
    >return individual elements of the array like "return newArray[3]" would
    >return the value of value4 in the code below but not the complete array.
    >
    ><html>
    > <head>
    > <title></title>
    >
    > <script language="javas cript">
    >function tmp(){
    >var newArray = new Array("value1", "value2","value 3","value4") ;
    >
    >return newArray????;
    >}
    >
    >function test(){
    >
    >document.write (tmp())
    >}
    > </script>
    > </head>
    > <body onload="test()" >
    >
    > </body>
    ></html>
    >
    >
    >Any guidance will be appreciated.[/color]

    Your argument passing is fine as written.
    Don't call document.write( ) in the body's onload handler.
    That makes the page load, and then changes the contents.
    It's better to call your function as the body is loading:


    <html>
    <head>
    <title></title>
    <script type="text/javascript">
    function tmp(){
    var newArray = new Array("value1", "value2","value 3","value4") ;
    return newArray;
    }

    function test(){
    document.write( tmp())
    }
    </script>
    </head>
    <body>
    <script type="text/javascript">
    test();
    </script>

    </body>
    </html>

    Comment

    • CES

      #3
      Re: Returning the complete contents of an array to another function

      Lee,
      That was 3 hours out of my life...
      Thank You.
      CES
      "Lee" <REM0VElbspamtr ap@cox.net> wrote in message
      news:blvmmd0b6f @drn.newsguy.co m...[color=blue]
      > CES said:[color=green]
      > >
      > >All,
      > >
      > >Sorry for the 101 question but I can't figure out how to return all of[/color][/color]
      the[color=blue][color=green]
      > >contents of an array to another function. I been able to figure out how[/color][/color]
      to[color=blue][color=green]
      > >return individual elements of the array like "return newArray[3]" would
      > >return the value of value4 in the code below but not the complete array.
      > >
      > ><html>
      > > <head>
      > > <title></title>
      > >
      > > <script language="javas cript">
      > >function tmp(){
      > >var newArray = new Array("value1", "value2","value 3","value4") ;
      > >
      > >return newArray????;
      > >}
      > >
      > >function test(){
      > >
      > >document.write (tmp())
      > >}
      > > </script>
      > > </head>
      > > <body onload="test()" >
      > >
      > > </body>
      > ></html>
      > >
      > >
      > >Any guidance will be appreciated.[/color]
      >
      > Your argument passing is fine as written.
      > Don't call document.write( ) in the body's onload handler.
      > That makes the page load, and then changes the contents.
      > It's better to call your function as the body is loading:
      >
      >
      > <html>
      > <head>
      > <title></title>
      > <script type="text/javascript">
      > function tmp(){
      > var newArray = new Array("value1", "value2","value 3","value4") ;
      > return newArray;
      > }
      >
      > function test(){
      > document.write( tmp())
      > }
      > </script>
      > </head>
      > <body>
      > <script type="text/javascript">
      > test();
      > </script>
      >
      > </body>
      > </html>
      >[/color]


      Comment

      Working...