hd-utils
Version:
A handy utils for modern JS developers
9 lines (8 loc) • 455 B
TypeScript
/**
* @description It takes a string, an object, and a navigation character, and returns the value of the object at the
* string's path.
* @example getObjectValueByPath({foo:{bar:"baz"}}, "foo.bar") // "baz"
* @example getObjectValueByPath({b:{ f: [1, 2, 3]}}, 'b.f[2]') // 3
* @returns The value of the key in the object.
*/
export default function getObjectValueByPath<T>(obj: Record<string, any>, path: string, navigationChr?: string): T | null;