View Full Version : Test for an object

12-19-2002, 09:50 PM
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?

12-19-2002, 10:07 PM
you have to use typeof
try this:

if ( typeof(name_of_array[value])!="undefined") {process to execute} else {}

12-19-2002, 10:13 PM
Tried it ConfusedOfLife but I still get the same error message as before.

12-19-2002, 11:05 PM
how are you declaring name_of_array[value] ??

12-19-2002, 11:56 PM
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.