[flexcoders] Best Practices: determining if a key is in an Object?

2005-12-08 Thread sbyrne_dorado
I'd like to find out what the best (most efficient) way to determine if a given key is present in an object. obj[key] will answer undefined if either there is no key in object, OR if it's value is in fact undefined. I can of course to the potentially expensive for..in and break out if I find

Re: [flexcoders] Best Practices: determining if a key is in an Object?

2005-12-08 Thread JesterXL
Not sure about effecient (have some tests at bottom), but the correct way is to use: // notice 3 equals if ( o.prop === undefined) { // does not have prop } else { // DOES have prop } null is a valid value, whereas undefined means the property doesn't exist. hasOwnProperty doesn't look