Toolbox-XToolbox-X

Extract Object Entries

Extracts the top-level entries of an object as key-value pairs with proper typing.

extractObjectEntries

The extractObjectEntries function extracts the top-level entries of an object as an array of key-value pairs (tuples) with proper TypeScript typing. It safely handles null and undefined inputs by returning an empty array [].

Function Signature

function extractObjectEntries<T extends GenericObject>(obj: T): Array<ObjectEntry<T>>

Parameters

  • obj (T): The object from which to extract entries.

Return Value

  • Array<ObjectEntry<T>>: An array of [key, value] tuples representing the enumerable own properties of the object. Returns an empty array if the input is null, undefined or non-object value.

Example Usage

playground.ts

Type Safety

Unlike standard Object.entries(obj), which types the keys as string[] and values as any[], extractObjectEntries preserves the literal keys of the object and types the values according to their specific keys using the ObjectEntry<T> utility type.

Aliases

The following aliases can be used for the extractObjectEntries function:

  • extractEntries
  • objectEntries

Last updated: Sun, Jun 14, 2026 07:15:25PM (UTC)

On this page