Determines whether the sequence contains at least one element that matches the optional predicate.
Type of elements within the source iterable.
source
The source iterable.
Optional
Optional function used to test elements. When omitted, the function returns true if source contains any element.
true
true when a matching element is found; otherwise, false.
false
When the predicate is omitted, only the first element is inspected, making this more efficient than count(source) > 0.
count(source) > 0
const numbers = [1, 2, 3, 4, 5];const hasEvenNumber = any(numbers, x => x % 2 === 0);console.log(hasEvenNumber); // trueconst oddNumbers = [1, 3, 5];const hasEvenNumber2 = any(oddNumbers, x => x % 2 === 0);console.log(hasEvenNumber2); // false Copy
const numbers = [1, 2, 3, 4, 5];const hasEvenNumber = any(numbers, x => x % 2 === 0);console.log(hasEvenNumber); // trueconst oddNumbers = [1, 3, 5];const hasEvenNumber2 = any(oddNumbers, x => x % 2 === 0);console.log(hasEvenNumber2); // false
Determines whether the sequence contains at least one element that matches the optional predicate.