Function filterObject

  • Filter the entries of an object using a predicate function

    Returns

    obj with entries removed as determined by predFn

    Example

    const people = { john: { age: 32 }, alice: { age: 23 } }
    const olderPeople = filterObject(people, (_name, person) => person.age > 25)
    olderPeople === { john: { age: 32 } }

    Example

    const people = { john: { age: 32 }, alice: { age: 23 } }
    const aPeople = filterObject(people, (name, _person) => name.startsWith('a'))
    expect(aPeople).toEqual({ alice: { age: 23 } })

    Type Parameters

    • TObj extends Record<PropertyKey, any>

    Parameters

    • obj: TObj

      the object to filter

    • predFn: ((key, value, object) => boolean)

      the predicate function

        • (key, value, object): boolean
        • Parameters

          • key: keyof TObj
          • value: TObj[keyof TObj]
          • object: TObj

          Returns boolean

    Returns Partial<TObj>

Generated using TypeDoc