undefined array

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

    undefined array

    in javascript, is there a way to test if an array is undefined????


    eg...
    for (var x=0; x<10; x++){
    if test_array[x] is undefined then x++
    document.write( test_array[x])

    if anyone can help, thanks... oh and if you can get the syntex right for me
    thanks..





  • Grant Wagner

    #2
    Re: undefined array

    OzThor wrote:
    [color=blue]
    > in javascript, is there a way to test if an array is undefined????
    >
    > eg...
    > for (var x=0; x<10; x++){
    > if test_array[x] is undefined then x++
    > document.write( test_array[x])
    >
    > if anyone can help, thanks... oh and if you can get the syntex right for me
    > thanks..[/color]

    for (var x = 0; x < 10; x++) {
    if (typeof test_array[x] == 'undefined') {
    continue;
    }

    document.write( test_array[x]);
    }

    or

    for (var x = 0; x < 10; x++) {
    if (typeof test_array[x] != 'undefined') {
    document.write( test_array[x]);
    }
    }

    --
    | Grant Wagner <gwagner@agrico reunited.com>

    * Client-side Javascript and Netscape 4 DOM Reference available at:
    *


    * Internet Explorer DOM Reference available at:
    *
    Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.


    * Netscape 6/7 DOM Reference available at:
    * http://www.mozilla.org/docs/dom/domref/
    * Tips for upgrading JavaScript for Netscape 7 / Mozilla
    * http://www.mozilla.org/docs/web-deve...upgrade_2.html


    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: undefined array

      "OzThor" <ronjeff@ncable .net.au> writes:
      [color=blue]
      > in javascript, is there a way to test if an array is undefined????[/color]

      If it's undefined, then it isn't an array :)
      [color=blue]
      > eg...
      > for (var x=0; x<10; x++){
      > if test_array[x] is undefined then x++
      > document.write( test_array[x])[/color]

      Ah, you want to know whether the array element is undefined.

      for (var i=0;i<10;i++) {
      if (typeof test_array[i] != "undefined" ) {
      document.write( test_array[i]);
      }
      }

      Good luck
      /L
      --
      Lasse Reichstein Nielsen - lrn@hotpop.com
      DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
      'Faith without judgement merely degrades the spirit divine.'

      Comment

      • Vax

        #4
        Re: undefined array

        [...]
        [color=blue]
        > for (var x = 0; x < 10; x++) {
        > if (typeof test_array[x] != 'undefined') {
        > document.write( test_array[x]);
        > }
        > }[/color]

        or

        for(var x,y;x<10;x++)if (test_array[x]!=y)document.wr ite(test_array[x])

        (y is declared, but undefined)

        v.


        Comment

        • Vax

          #5
          Re: undefined array

          for(var y,x=0;x<10;x++) if(test_array[x]!=y)document.wr ite(test_array[x])

          (y is declared, but undefined)

          v.



          Comment

          • Richard Cornford

            #6
            Re: undefined array

            Vax wrote:[color=blue]
            > for(var
            > y,x=0;x<10;x++) if(test_array[x]!=y)document.wr ite(test_array[x])
            >
            > (y is declared, but undefined)[/color]

            Using the type-converting comparison - != - means that - null - values
            will also be true in - if(test_array[x] != y) - and - null - values are
            not undefined. Either a typeof test or the strict (non-type
            converting) - !== - comparison are probably the only way to truly
            identify undefined array members.

            Richard.


            Comment

            • Vax

              #7
              Re: undefined array


              U¿ytkownik "Richard Cornford" <Richard@litote s.demon.co.uk> napisa³ w
              wiadomo¶ci news:c8jkel$nq6 $1$8302bc10@new s.demon.co.uk.. .[color=blue]
              > Vax wrote:[color=green]
              > > for(var
              > > y,x=0;x<10;x++) if(test_array[x]!=y)document.wr ite(test_array[x])
              > >
              > > (y is declared, but undefined)[/color]
              >
              > Using the type-converting comparison - != - means that - null - values
              > will also be true in - if(test_array[x] != y) - and - null - values are
              > not undefined.[/color]

              yes, but try:
              javascript:x=nu ll;alert(x==und efined)
              javascript:var x=0;alert(x==un defined)
              javascript:var x=false;alert(x ==undefined)

              problem is only(?) with "null"...

              v.


              Comment

              • Richard Cornford

                #8
                Re: undefined array

                Vax wrote:[color=blue]
                > "Richard Cornford" wrote:[color=green]
                >> Vax wrote:[color=darkred]
                >>> for(var
                >>> y,x=0;x<10;x++) if(test_array[x]!=y)document.wr ite(test_array[x])
                >>>
                >>> (y is declared, but undefined)[/color]
                >>
                >> Using the type-converting comparison - != - means that - null -
                >> values will also be true in - if(test_array[x] != y) - and - null -
                >> values are not undefined.[/color]
                >
                > yes, but try:
                > javascript:x=nu ll;alert(x==und efined)
                > javascript:var x=0;alert(x==un defined)
                > javascript:var x=false;alert(x ==undefined)
                >
                > problem is only(?) with "null"...[/color]

                That is what I said, but - null - and - undefined - are still distinct.

                Richard.


                Comment

                Working...