It depends on what you are really trying to test:

- Are you trying to test whether the property exists at all?
- Are you trying to test whether it exists and has a non-null value?

The verbose but foolproof way to test whether it exists at all is to 
use Object.hasOwnProperty().  To test if object o has 
property 'wwwrgrwr':

if (o.hasOwnProperty('wwwrgwr')) ...

If you know that object o['blahblah'] exists, you want to test 
whether *that* object has its own property 'something':

if (o['blahblah'].hasOwnProperty('something') ...

To test whether it has an, umm, non-false value, do this:

if (o.blahblah) ...

But note that that is kind of subtle.  If blahblah is guaranteed to 
point to some sort of Object, then that's fine.  But what if blahblah 
is equal to false?  What if blahblah is equal to zero?  In both of 
those cases, blahblah exists, but the "if" test will return false.

And then there are these:

if (o.blahblah != undefined) ...
if (o.blahblah != null) ...

It's tricky stuff.

My guess, from the context, is that you are trying to test if 
blahblah exists and is a reference to some other object.  In that 
case, I would use this (which, conveniently, is the simplest to 
write):

if (o.blahblah) ...



--- In flexcoders@yahoogroups.com, "rigidcode" <[EMAIL PROTECTED]> wrote:
>
> 
> If I have an hash (object) like this:
> 
> var o:Object = new Object();
> o['blahblah'];
> 
> How do I test if there exists an o['wwwrgwr']?  
> 
> I had a situation where I set something to a string:
> o['blahblah']='wefwefw';
> 
> and then later tried:
> 
> if (o['blahblah']['something']) {
> 
> }
> 
> and I got:
> "Property value not found on String" 
> 
> How do I test if there is exists an o['blahblah']['something'] ?
> 
> thanks
>






--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/flexcoders/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[EMAIL PROTECTED] 
    mailto:[EMAIL PROTECTED]

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to