Function filter

  • Returns values where predicate returns true.

    If you just want the first match, use find

    Type Parameters

    • V

    Parameters

    • map: ReadonlyMap<string, V>

      Map

    • predicate: ((v: V) => boolean)

      Filtering predicate

        • (v): boolean
        • Parameters

          Returns boolean

    Returns Generator<V, void, unknown>

    Values that match predicate

    // for-of loop
    for (const v of filter(people, person => person.age > 30)) {

    }
    // If you want an array
    const overThirty = Array.from(filter(people, person => person.age > 30));