@nevware21/ts-utils
    Preparing search index...

    Function arrTakeWhile

    • The arrTakeWhile() method returns a new array containing elements from the beginning of the array as long as the predicate function returns true. Once the predicate returns false, iteration stops.

      Type Parameters

      • T

        Identifies the base type of array elements

      • E = T

        Identifies the narrowed type when using type guards

      Parameters

      • theArray: ArrayLike<T>

        The array or array-like object to take from

      • callbackFn: ArrPredicateCallbackFn<T, E> | ArrPredicateCallbackFn2<T>

        Function to test each element. Return true to continue, false to stop

      • OptionalthisArg: any

        Optional value to use as this when executing callbackFn

      Returns T[] | E[]

      A new array containing elements until the predicate returns false

      0.14.0

      arrTakeWhile([1, 2, 3, 4, 1], x => x < 3);      // [1, 2]
      arrTakeWhile([2, 4, 6, 1, 8], x => x % 2 === 0); // [2, 4, 6]
      arrTakeWhile([1, 2, 3], x => x > 5); // []
      arrTakeWhile([1, 2, 3], x => x < 5); // [1, 2, 3]

      // Array-like objects
      arrTakeWhile({ length: 4, 0: 1, 1: 2, 2: 3, 3: 4 }, x => x < 3); // [1, 2]