How to check whether a Javascript object has a value for a given key?
dictionary, javascript, key
Solution
if ('X' in mmap)
{
// ...
}
Here is an example on JSFiddle.
`hasOwnProperty` is also valid, but using `in` is much more painless. The only difference is that `in` returns prototype properties, whereas `hasOwnProperty` does not.
Problem
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?