Skip to main content

Function: contains()

contains<ElementType>(iterable: IterableResolvable<ElementType>, value: ElementType): boolean

Advances the iterable until it finds the element, returning true if it's found and false otherwise.

Type Parameters

Type Parameter
ElementType

Parameters

ParameterTypeDescription
iterableIterableResolvable<ElementType>The iterator in which to locate a value.
valueElementTypeThe value to locate in the iterator.

Returns

boolean

true if the value is found in the iterator; otherwise, false.

Example

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

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

Remarks

This function consumes the iterator until the value is found or the iterator is exhausted.

Defined in

projects/utilities/packages/iterator-utilities/src/lib/contains.ts:24