javascript check if object in array has property code example
Example 1: javascript check if value exists in array of objects
var arr = [{ id: 1, name: 'JOHN' },
{ id: 2, name: 'JENNIE'},
{ id: 3, name: 'JENNAH' }];
function userExists(name) {
return arr.some(function(el) {
return el.name === name;
});
}
console.log(userExists('JOHN'));
console.log(userExists('JUMBO'));
Example 2: array has object with property js
myArray.some(obj => obj.property === 'value')
Example 3: angular list contains property
vendors.filter(function(vendor){ return vendor.Name === "Magenic" })
Example 4: check if property has value in array javascript
const magenicVendorExists = vendors.reduce((accumulator, vendor) => (accumulator||vendor.Name === "Magenic"), false);