Function filter

  • Iterates over elements of array, returning an array of all elements predicate returns truthy for. The predicate is invoked with three arguments: (value, index, array).

    Note: Unlike remove, this method returns a new array.

    Type Parameters

    • T
    • S

    Parameters

    • array: T[]

      The array to iterate over.

    • predicate: ArrayIteratorTypeGuard<T, S>

      The function invoked per iteration.

    Returns S[]

    Returns the new filtered array.

    5.0.0

    pull, pullAll, pullAllBy, pullAllWith, pullAt, remove, reject

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

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