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
    Jul 2002
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Test for an object

    I am looking for a way to test if something is an object.

    I have an array and I need a test function that would check if a proposed value exist in that array. I tried this:

    if (name_of_array[value]!=Null) {process to execute} else {}

    but I get this message: name_of_array[value] has a Null value or is not an object.

    I would like to test if "name_of_array[value]" is an object and then do some thing else.

    Any one has an idea?
    Daniel

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    Iran
    Posts
    695
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you have to use typeof
    try this:
    Code:
    if ( typeof(name_of_array[value])!="undefined") {process to execute} else {}

  • #3
    New Coder
    Join Date
    Jul 2002
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Tried it ConfusedOfLife but I still get the same error message as before.
    Daniel

  • #4
    Regular Coder
    Join Date
    Sep 2002
    Location
    Louisiana
    Posts
    576
    Thanks
    0
    Thanked 0 Times in 0 Posts
    how are you declaring name_of_array[value] ??

  • #5
    New Coder
    Join Date
    Jul 2002
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks guys I found my answer. The typeof test works now. My first attempt didn't work because I was typing !=undefined instead of !="undefined". With the quotes, it works. Thanks again.
    Daniel


  •  

    Posting Permissions

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