Skip to main content

Function: count()

count<ElementType>(iterable: IterableResolvable<ElementType>): number

Consumes the iterable and returns the number of elements.

Type Parameters

Type Parameter
ElementType

Parameters

ParameterTypeDescription
iterableIterableResolvable<ElementType>An iterator that contains elements to be counted.

Returns

number

The number of elements in the input iterator.

Example

import { count } from '@sapphire/iterator-utilities';

const iterable = [1, 2, 3, 4, 5];
console.log(count(iterable));
// Output: 5

Remarks

This function consumes the entire iterator.

Defined in

projects/utilities/packages/iterator-utilities/src/lib/count.ts:22