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')); // true
console.log(userExists('JUMBO')); // false
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')); // true
console.log(userExists('bred')); // false
function containsObject(obj, list) {
var i;
for (i = 0; i < list.length; i++) {
if (list[i] === obj) {
return true;
}
}
return false;
}