📌  相关文章
📜  如何检查对象数组中是否存在元素js - Javascript代码示例

📅  最后修改于: 2022-03-11 15:02:46.478000             🧑  作者: Mango

代码示例2
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