Finds a nested object in an object by searching for a property and value.
Parameters:
Name | Type | Description |
---|---|---|
objToSearch | object | The object to search. |
propToSearch | string | The property to search for. |
valueToMatch | string | The value to match. |
- Since
- 2.0.1
- Source
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