Finds a nested object in an object by searching for a property and value.

Parameters:
NameTypeDescription
objToSearchobject

The object to search.

propToSearchstring

The property to search for.

valueToMatchstring

The value to match.

Since
  • 2.0.1
Returns:
Type: 
object | null
Example
import { findNestedObject } from "@gravityforms/utils";

const obj = {
 foo: {
 bar: {
 baz: 'hello',
 },
 },
 };
 const found = findNestedObject( obj, 'baz', 'hello' );
 console.log( found ); // { baz: 'hello' }
 const notFound = findNestedObject( obj, 'baz', 'goodbye' );
 console.log( notFound ); // null