Let’s see how to check if an Object contains a key in JavaScript. You’ll be making use of the Object.keys method in JavaScript to check if a key exists in an object.

let obj = {"name": "roy", "age" : 24};
let keyToFind = "age";
let keyList = Object.keys(obj);

The above code returns the list of keys available in the Object obj. Now you need to check if the key that we are looking for exists in the keyList. You can make use of the Array.includes method to check if the key exists in the array.

let obj = {"name": "roy", "age" : 24};
let keyToFind = "age";
let keyList = Object.keys(obj);
if(keyList.length > 0){
  if(keyList.includes(keyToFind)){
    console.log("Objects contains key");
  } else {
    console.log("Object doesn't contain key");
  }
}