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.

Source

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