Loops
/ API Reference
Loops
/ API Reference

objectFind

Finds the first key-value pair in the object that matches the provided query function.
Similar to Array.prototype.find, but for objects.

The Gist

import { objectFind } from '@weser/loops'

const foundObject = objectFind({ a: 1, b: 2, c: 3 }, (value) => value > 1)

// => 'b'
console.log(foundObject)

Parameters

ParameterTypeDescription
objRecord<PropertyKey, any>The object to find.
query(value: any, key: PropertyKey, obj: Record<PropertyKey, any>) => booleanThe query function.

Returns

(PropertyKey | undefined) The found object key or undefined if no match is found.

On this page