Function filter

  • Iterates over elements of collection, returning an array of all elements where predicate returns truthy value.

    The predicate is invoked with three arguments: (value, index|key, arr).

    Example

    let users = [
    { 'user': 'barney', 'age': 36, 'active': true },
    { 'user': 'fred', 'age': 40, 'active': false }
    ]

    filter(users, o => !o.active)
    // objects for ['fred']

    // The shape iteratee shorthand.
    filter(users, { age: 36, active: true })
    // objects for ['barney']

    // The property iteratee shorthand.
    filter(users, 'active')
    // objects for ['barney']

    Returns

    The new filtered array

    Type Parameters

    • T

    Parameters

    • arr: T[]

      The collection to iterate over

    • Optional fn: Iteratee<T, any, any>

      The predicate function invoked for each item

    Returns T[]

  • Type Parameters

    • T

    Parameters

    • arr: T[]
    • Optional fn: Object

    Returns T[]

  • Type Parameters

    • T

    Parameters

    • arr: Object
    • Optional fn: Iteratee<T, any, any>

    Returns T[]

  • Type Parameters

    • T

    Parameters

    • arr: Object
    • Optional fn: Object

    Returns T[]

Generated using TypeDoc