@bnidev/js-utils
    Preparing search index...

    Function pick

    • Creates a new object composed of the specified keys from the input object.

      Type Parameters

      • T extends object

        The type of the source object.

      • K extends string | number | symbol

        The keys to pick from the source object.

      Parameters

      • obj: T

        The source object to pick properties from.

      • keys: K[]

        An array of keys to include in the returned object.

      Returns Pick<T, K>

      A new object with only the specified keys.

      const user = { id: 1, name: 'Alice', age: 30 }
      const result = pick(user, ['id', 'name'])
      // result: { id: 1, name: 'Alice' }