当前位置: 首页 > 文档资料 > Lazy.js 英文文档 >

find

优质
小牛编辑
128浏览
2023-12-01

Seaches for the first element in the sequence satisfying a given predicate.

Signature

Sequence.find = function(predicate) { /*...*/ }
Sequence.find = function find(predicate) {
  return this.filter(predicate).first();
}
NameType(s)Description
predicateFunction

A function to call on (potentially) every element in the sequence.

returns*

The first element in the sequence for which predicate returns true, or undefined if no such element is found.

Examples

function divisibleBy3(x) {
  return x % 3 === 0;
}

var numbers = [5, 6, 7, 8, 9, 10];

Lazy(numbers).find(divisibleBy3) // => 6
Lazy(numbers).find(isNegative)   // => undefined