For the sake of completeness, you can use the in operator. This is probably the best way to check for missing keys.
1 2 3 4 5 6 7 8 | var hi = {hello: "world" }; alert( hi[ "hello" ] ); // popup box with "world" alert( hi[ "goodbye" ] ); // popup boc with "undefined" // this works even if you have {"goodbye": undefined} if ( "goodbye" in hi ) { // do something } |
What do you think?