Toolbox-XToolbox-X

Pick Object Fields By Condition

Creates a new object containing only the properties that satisfy a given condition.

pickObjectFieldsByCondition

The pickObjectFieldsByCondition function filters an object's properties by evaluating a predicate function (condition) against each key-value pair.

Function Signature

function pickObjectFieldsByCondition<T extends GenericObject>(
  source: T,
  condition: (key: keyof T, value: T[keyof T]) => boolean
): Partial<T>

Parameters

  • source (T): The source object to filter.
  • condition ((key: keyof T, value: T[keyof T]) => boolean): A function evaluated for each property. Return true to keep the property, or false to omit it.

Return Value

  • Partial<T>: A new object containing only the properties that satisfy the condition.

Example Usage

playground.ts

Notes

  • This function operates on top-level properties only. It does not recursively inspect nested objects.
  • It is non-destructive and returns a new object without mutating the original source.

Aliases

The following aliases can be used for the pickObjectFieldsByCondition function:

  • pickFieldsByCondition

Last updated: Sun, Jun 14, 2026 07:06:16AM (UTC)

On this page