check if value exists in object javascript code example
Example 1: search if value exists in object javascript
var exists = Object.keys(obj).some(function(k) {
return obj[k] === "test1";
});
Example 2: how to check if object exists in javascript
if (typeof maybeObject != "undefined") {
alert("GOT THERE");
}
Example 3: test if property exists javascript
const hero = {
name: 'Batman'
};
hero.hasOwnProperty('name');
hero.hasOwnProperty('realName');
Example 4: check if field exists in object javascript
if ('field' in obj) {
}