views:

1192

answers:

2

which is the right thing to do?

if (myObj['key']==undefined)

or

if (myObj['key']==null)

or

if (myObj['key'])


Exact duplicate of: http://stackoverflow.com/questions/135448/how-do-i-check-to-see-if-an-object-has-an-attribute-in-javascript

+2  A: 

hasOwnProperty

Typeoneerror
TypeOneError,thanks, but is this supported in IE, safari? It looks like it is not supporteD?
+4  A: 

Try the javascript in operator.

if('key' in myObj)
ForYourOwnGood