how to use includes in javascript array of objects code example
Example 1: how to check if an element exists in an array of objects js
var arr = [{ id: 1, username: 'fred' },
{ id: 2, username: 'bill'},
{ id: 3, username: 'ted' }];
function userExists(username) {
return arr.some(function(el) {
return el.username === username;
});
}
console.log(userExists('fred'));
console.log(userExists('bred'));
Example 2: angular list contains property
vendors.filter(function(vendor){ return vendor.Name === "Magenic" })