TS-Scribe - v0.6.2
    Preparing search index...

    Function pickObjectKeys

    • Creates a new object containing only the specified keys from the original object. This function avoids mutating the original object by creating a new object.

      Type Parameters

      • T extends object

        The type of the object from which keys will be picked.

      • K extends string | number | symbol

        The keys of the object to be picked.

      Parameters

      • object: T

        The object from which keys will be picked.

      • keys: K[]

        The array of keys to pick from the object.

      Returns Pick<T, K>

      A new object containing only the specified keys.

      const original = { a: 1, b: 2, c: 3 };
      const result = pickObjectKeys(original, ['a', 'c']);
      console.log(result); // { a: 1, c: 3 }

      const user = { name: 'Alice', age: 25, country: 'USA' };
      const pickedData = pickObjectKeys(user, ['name', 'age']);
      console.log(pickedData); // { name: 'Alice', age: 25 }