Loading...
const hasAdmin = users.values()
.filter((u) => u.role === 'admin')
.toArray().length > 0;const hasAdmin = users.values()
.some((u) => u.role === 'admin');some() stops at the first admin and returns a boolean, instead of collecting every match into an array.
some() returns true.some() is used instead of find() when only a boolean is needed.some(), because it stops at the first match.some() return for an empty iterator?false, because no value passed the test.
some() the same as array some()?It gives the same answer, but works on any iterator, reads values lazily and closes the iterator after the first match.