i new javascript. codes, want return true if finds 'anna' in list
var userlist = [{'username':'anna','email':'anna@a.c'}, {'username':'benny','email':'benny@a.c'}, {'username':'kathy','email':'kathy@a.c'}] return userlist.includes('anna')
your appreciated
use some
:
es6 syntax:
return userlist.some(user => user.username === 'anna');
es5 syntax:
function hasanna(user) { return user.username === 'anna'; } return userlist.some(hasanna);
Comments
Post a Comment