🧩 Creates a slice of array with elements dropped from the beginning or end while the predicate returns true.

Syntax

TypeScript
import { dropWhile } from '@opentf/std';

dropWhile<T>(arr: T[] = [], predicate: (val: T, index: number, arr: T[]) => boolean, right?: boolean): T[]

Parameters

  • arr: The source array.

  • predicate: The function invoked per element. Receives (value, index, array).

  • right: If true, drops from the end while preserving the original callback indexes and array.

Returns

A new array with dropped elements removed.

Examples

TypeScript
dropWhile([1, 2, 3, 4, 5], (n) => n < 3) //=> [3, 4, 5]

dropWhile([1, 2, 3], (n) => n > 3) //=> [1, 2, 3]

dropWhile([1, 2, 3], (n) => n < 10) //=> []

dropWhile([false, false, true, false], (v) => !v) //=> [true, false]

dropWhile([1, 2, 3, 4, 5], (n) => n > 3, true) //=> [1, 2, 3]
Last updated on
Edit this page