Loading...
const user = [...users.values()]
.find((u) => u.email === email);
console.log(user.name);const user = users.values()
.find((u) => u.email === email);
console.log(user?.name ?? 'Not found');find() searches the iterator directly and stops at the match; optional chaining handles the undefined result.
find(), which has already closed it.find() is used instead of converting the iterator to an array and calling find() on it.undefined when no value matches.findIndex() for iterators?No. The callback's second argument is a counter, so you can record it when the test passes.
find() and filter() on an iterator?find() returns the first matching value and stops. filter() returns a new iterator over all matching values.