Tweakr
    Preparing search index...

    Function filterKeys

    • Creates a new object containing only the keys from the original object that satisfy the given predicate function.

      Type Parameters

      • T extends object
      • K extends string | number | symbol

      Parameters

      • obj: T

        The source object to filter keys from.

      • predicate: (key: K) => boolean

        A function that receives each key and returns true to keep it.

      Returns Partial<T>

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

      const obj = { a: 1, b: 2, c: 3 };
      const filtered = filterKeys(obj, key => key !== 'b');
      console.log(filtered); // { a: 1, c: 3 }

      1.1.0