JavaScriptの連想配列にキーが存在するか確認する

JavaScriptの連想配列にキーが存在するか確認する方法です。

inはこのような使い方してはいけないとのご指摘を頂き修正しました。

var hash = { a: 1,  b: 2 };

// inを使った悪い例
console.log('a' in hash); //true
console.log('c' in hash); //false

// hasOwnPropertyを使った例
console.log(hash.hasOwnProperty('a')); //true
console.log(hash.hasOwnProperty('c')); //false