Tweakr
    Preparing search index...

    Function filterValues

    • Creates a new object containing only the key-value pairs from the original object whose values satisfy the given predicate function.

      Type Parameters

      • T extends object

      Parameters

      • obj: T

        The source object to filter values from.

      • predicate: (value: T[keyof T], key: keyof T) => boolean

        A function that receives each value and key, returning true to keep the pair.

      Returns Partial<T>

      A new object containing only the key-value pairs where the value passed the predicate.

      const obj = { a: 1, b: 2, c: 3 };
      const filtered = filterValues(obj, value => value > 1);
      console.log(filtered); // { b: 2, c: 3 }

      1.1.0