Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

actionscript (flex): how to know whether a property of object exists (or defined)?

I am a Java developer who tries Flex. Here is my problem:

I behave actionScript objects as hashmap but when the object do not have the property it gives exception: No such variable.

Here I expect it gave me null, instead of giving exception. So do you know is there a way to handle it, namely check if the property is defined for object.

trace( obj["2008-02"] ) // gives exception

like image 692
enesness Avatar asked Oct 05 '09 14:10

enesness


People also ask

How to check if property exists in object javascript?

The first way is to invoke object. hasOwnProperty(propName) . The method returns true if the propName exists inside object , and false otherwise. hasOwnProperty() searches only within the own properties of the object.


1 Answers

Use something along the lines of

if (myObject.hasOwnProperty("propertyName"))

to check if the property exists.

Edit: Also take a look here.

like image 136
Dimitar Dimitrov Avatar answered Oct 14 '22 04:10

Dimitar Dimitrov