@nickyzj2023/utils
    Preparing search index...

    Function omitBy

    • 从对象中排除满足条件的键值对,返回不包含这些键的新对象

      Type Parameters

      • T extends Record<string, any>

        源对象的类型

      Parameters

      • obj: T

        源对象

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

        判断函数,接收键和值,返回 true 则排除该键值对

      Returns Partial<T>

      不包含满足条件的键值对的新对象

      const user = {
      id: 1,
      name: "Alice",
      age: 25,
      password: "secret"
      };
      // { name: "Alice", password: "secret" }
      const stringFields = omitBy(user, (key, value) => typeof value === "number");