Options
All
  • Public
  • Public/Protected
  • All
Menu

Module filter

Index

References

Functions Collection

References

Renames and re-exports filter

Collection Functions

  • filter<T>(collection: T[], predicate?: Predicate<T>): T[]
  • filter<T>(collection: T[], predicate?: any): T[]
  • Iterates over elements of collection, returning an array of all elements predicate returns truthy for. The predicate is invoked with three arguments: (value, index|key, collection).

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

    since

    5.0.0

    see

    reject

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

    filter(users, function(o) { return !o.active; });
    // => objects for ['fred']

    // The `matches` iteratee shorthand.
    filter(users, { 'age': 36, 'active': true });
    // => objects for ['barney']

    // The `matchesProperty` iteratee shorthand.
    filter(users, ['active', false]);
    // => objects for ['fred']

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

    Type parameters

    • T

    Parameters

    • collection: T[]

      The collection to iterate over.

    • Optional predicate: Predicate<T>

      The function invoked per iteration.

    Returns T[]

    Returns the new filtered array.

  • Type parameters

    • T

    Parameters

    • collection: T[]
    • Optional predicate: any

    Returns T[]