tags:

views:

22

answers:

2

And ofcourse I want to do this code-wise. It's not that there isn't alternative to this problem I'm facing, just currious.

+2  A: 
if ('field' in obj) {
}
Peter Kruithof
ah, it's so easy, thanks!
Khoi
Note that exactly the same way you can check the existence of a key in an associative array (this is because usually objects **are** in fact associative arrays)
Andrea Zilio
yes, it's just like in Python. I didn't know.
Khoi
+1  A: 

This will ignore attributes passed down through the prototype chain.

if(obj.hasOwnProperty('field'))
{
    // Do something
}
Gary Chambers