object contains js 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: js does object contain value
var obj = { a: 'test1', b: 'test2' };
if (Object.values(obj).indexOf('test1') > -1) {
console.log('Value exists!');
}
Example 3: object contains property javascript
if (x.hasOwnProperty('y')) {}
if ('y' in x) {}
if (x?.y){}