javascript check object contains value code example
Example 1: check the properties of an object in javascript
for (var name in object) {
if (object.hasOwnProperty(name)) {
}
}
const hero = {
name: 'Batman'
};
hero.hasOwnProperty('name');
hero.hasOwnProperty('realName');
Example 2: test if property exists javascript
const hero = {
name: 'Batman'
};
hero.hasOwnProperty('name');
hero.hasOwnProperty('realName');
Example 3: js does object contain value
var obj = { a: 'test1', b: 'test2' };
if (Object.values(obj).indexOf('test1') > -1) {
console.log('Value exists!');
}