...

View Full Version : Test for an object



DanLap
12-19-2002, 10: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?

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


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

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

chrismiceli
12-20-2002, 12:05 AM
how are you declaring name_of_array[value] ??

DanLap
12-20-2002, 12:56 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum