Function takeWhile

  • Creates a slice of array with elements taken from the beginning. Elements are taken until predicate returns falsey. The predicate is invoked with three arguments: (value, index, array).

    Type Parameters

    • T

    Parameters

    • array: T[]

      The array to query.

    • predicate: ArrayIterator<T, boolean>

      The function invoked per iteration.

    Returns T[]

    Returns the slice of array.

    3.0.0

    const users = [
    { 'user': 'barney', 'active': true },
    { 'user': 'fred', 'active': true },
    { 'user': 'pebbles', 'active': false }
    ]

    takeWhile(users, ({ active }) => active)
    // => objects for ['barney', 'fred']