Getting Object "type"

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

    #1

    Getting Object "type"

    Hello All:
    I would like to expand upon the typeof operator.
    Using 'typeof' I can distinguish between string and
    array for instance, because typeof returns "object" for
    array.

    How can I programmaticall y distinguish between an Array and an Option,
    for instance?

    Thanks
    Tim
  • Mick White

    #2
    Re: Getting Object "type&quot ;

    Tim Johnson wrote:
    [color=blue]
    > Hello All:
    > I would like to expand upon the typeof operator.
    > Using 'typeof' I can distinguish between string and
    > array for instance, because typeof returns "object" for
    > array.
    >
    > How can I programmaticall y distinguish between an Array and an Option,
    > for instance?
    >[/color]

    alert([1,2,3].constructor == Array)

    Mick

    Comment

    • Tim Johnson

      #3
      Re: Getting Object "type&quot ;

      Mick White wrote:
      <...>[color=blue][color=green]
      >> How can I programmaticall y distinguish between an Array and an Option,
      >> for instance?
      >>[/color]
      >
      > alert([1,2,3].constructor == Array)[/color]

      Eureka!
      thanks
      tj

      Comment

      • Danny

        #4
        Re: Getting Object &quot;type&quot ;


        Well, there's a typeof OBJHERE:

        typeof ARRHERE; will return 'array' of a function 'function' of a string
        a 'string' and such.

        Danny


        On Mon, 27 Jun 2005 15:47:53 -0700, Tim Johnson <tim@johnsons-web.com>
        wrote:
        [color=blue]
        > Hello All:
        > I would like to expand upon the typeof operator.
        > Using 'typeof' I can distinguish between string and
        > array for instance, because typeof returns "object" for
        > array.
        >
        > How can I programmaticall y distinguish between an Array and an Option,
        > for instance?
        >
        > Thanks
        > Tim[/color]



        --
        Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

        Comment

        • Michael Winter

          #5
          Re: Getting Object &quot;type&quot ;

          On 26/06/2005 06:30, Danny wrote:

          [snip]
          [color=blue]
          > typeof ARRHERE; will return 'array' [...][/color]

          No, it won't. There are a limited number of returned types, and they
          correspond to the primitives (boolean, number, string, and undefined)
          with the addition of object, which is a catch-all for all objects
          (including arrays).

          The null type, which is also a primitive, does not have its own value
          and is classified as an object. Functions are also an exception but
          unlike null, they /do/ have their own value.

          [snipped top-post]

          Stop top-posting. This group has posting rules - follow them.

          Mike

          --
          Michael Winter
          Replace ".invalid" with ".uk" to reply by e-mail.

          Comment

          Working...