Counts the number of elements in the sequence, optionally restricted by a predicate.
Type of elements within the source iterable.
source
The source iterable.
Optional
Optional predicate that determines which elements are counted. When omitted, all elements are counted.
The number of elements that satisfy the predicate.
Prefer calling any(source) to test for existence instead of comparing this result with zero.
any(source)
const numbers = [1, 2, 3, 4, 5];const totalCount = count(numbers);console.log(totalCount); // 5const evenCount = count(numbers, x => x % 2 === 0);console.log(evenCount); // 2 Copy
const numbers = [1, 2, 3, 4, 5];const totalCount = count(numbers);console.log(totalCount); // 5const evenCount = count(numbers, x => x % 2 === 0);console.log(evenCount); // 2
Counts the number of elements in the sequence, optionally restricted by a predicate.