UPDATE: use the hasOwnProperty method as Gary Chambers suggests. The solution below will work, but it's considered best practice to use hasOwnProperty.
This question is quite old but it still can be useful to some people.
Now, there is an other way to do it which is recommended if you have non-hardcoded keys.
You have to go from this:
foo.hasOwnProperty("bar");
To this:
Object.prototype.hasOwnProperty.call(foo, "bar");
This update is particularly useful, especially if you use a linter like ESLint which has by default this rule in the "eslint:recommended" set of rules. This new way to do it is notably for security reasons. The whole explanation is available on this page.