DEV Community

Discussion on: JavaScript shorthand tips and tricks

Collapse
 
jonrandy profile image
Jon Randy 🎖️

Check if a key exists in an object

Your examples here will check if the property exists in the object itself OR in its prototype chain. To check if the property is on the object itself, you could check if it appears in Object.keys(obj), or use .hasOwnProperty(key) on the Object itself