Toolbox-XToolbox-X

Filter Array of Objects

Filters an array of objects based on multiple conditions.

filterArrayOfObjects

Tips

Please use the findAll instance method from the Finder class for more advanced filtering and searching.

Filters an array of objects based on multiple conditions for specified keys.

Function Signature

const filterArrayOfObjects = <T extends GenericObject>(array: Maybe<T[]>, conditions: ConditionFns<T>): T[]

Parameters

  • array (T[]): The array of objects to filter.
  • conditions ({ [K in keyof T]?: (value: Maybe<T[K]>) => boolean }): An object where keys represent property names and values are functions defining filter conditions.

Returns

  • T[]: The filtered array of objects.

Example

playground.ts

Type of Conditions Parameter

/** A function type that accepts a value and returns a boolean. */
type ConditionFn<T = unknown> = (value: Maybe<T>) => boolean;

/** An object type for storing multiple condition functions. */
type ConditionFns<T extends GenericObject> = {
	[K in keyof T]?: ConditionFn<T[K]>;
};

Last updated: Sun, Jun 14, 2026 08:22:19PM (UTC)

On this page