find
优质
小牛编辑
134浏览
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(); }
Name | Type(s) | Description |
---|---|---|
predicate | Function | A function to call on (potentially) every element in the sequence. |
returns | * | The first element in the sequence for which |
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