check if property value exists in array of objects javascript code example
Example 1: javascript does object have property
var person = {'first_name': 'bill','age':20};
if ( person.hasOwnProperty('first_name') ) {
}
Example 2: check if object is present in array javascript
function containsObject(obj, list) {
var i;
for (i = 0; i < list.length; i++) {
if (list[i] === obj) {
return true;
}
}
return false;
}
function containsObject(obj, list) {
var x;
for (x in list) {
if (list.hasOwnProperty(x) && list[x] === obj) {
return true;
}
}
return false;
}