How To Check If Object Has Key In JavaScript


In this tutorial, you’ll learn how to check if an object has key in JavaScript. You’ll be making use of in operator for checking if a key is present or not.

let obj = {
    'name' : 'Roy'
}

if('name' in obj){
    console.log('Found')
} else {
    console.log('Not found')
}