• 过滤对象属性

    代替Object.keys(target).filter()

    参数

    • obj: Record<string, any>
    • predicate: ((v: any, k: string) => boolean) = ...
        • (v, k): boolean
        • 参数

          • v: any
          • k: string

          返回 boolean

    返回 object

    const obj = { a: '', b: 123, c: 0, d: undefined, e: false, f: NaN, g: null };
    filterObj(obj); // { b: 123 }
    filterObj(obj, (v) => v !== undefined); // omit(obj, ['d'])