@supuwoerc/toolkit
    Preparing search index...

    Function pick

    • 从源对象中选取指定属性,返回新对象 Picks specified properties from source object and returns new object

      Type Parameters

      • O extends object

        源对象类型 / Source object type

      • K extends string | number | symbol

        选取的属性键类型 / Keys type to pick

      Parameters

      • source: O

        源对象 / Source object

      • keys: readonly K[]

        要选取的属性键数组 / Array of keys to pick

      • OptionalomitUndefined: boolean = false

        是否忽略undefined值,默认false / Whether to omit undefined values, default false

      Returns Pick<O, K>

      选取后的新对象 / New object with picked properties

      // 基础用法 / Basic usage
      const obj = { a: 1, b: 2, c: 3 }
      pick(obj, ['a', 'c']) // { a: 1, c: 3 }
      // 忽略undefined值 / Omit undefined values
      const obj = { a: 1, b: undefined, c: 3 }
      pick(obj, ['a', 'b', 'c'], true) // { a: 1, c: 3 }