Possible Duplicate:
How do I check to see if an object has an attribute in Javascript?
I have a Javascript object defined as following:
var mmap = new Object();
mmap['Q'] = 1;
mmap['Z'] = 0;
mmap['L'] = 7;
...
How to check whether this map has a value for a given key (for example ‘X’)? Does .hasOwnProperty() get into play?
Here is an example on JSFiddle.
hasOwnPropertyis also valid, but usinginis much more painless. The only difference is thatinreturns prototype properties, whereashasOwnPropertydoes not.