how to check if object has key javascript
snippet in javascript

how to check if object has key javascript

user765

myObj.hasOwnProperty('key') // it checks object for particular key and not on prototype   

check if a key exists in an object javascript

user4501

"key" in obj // true, regardless of the actual value

typescript check if object has key

user8254

if ('key' in myObj)

js object contain key

user3864

if ('key' in myObj)
// better
if (!myObj.hasOwnProperty('key'))