10 lines
389 B
TypeScript
10 lines
389 B
TypeScript
/**
|
|
* Retrieves a nested value from an object using dot notation path
|
|
* @param path - Dot-separated path (e.g., "user.address.city")
|
|
* @param obj - Object to extract value from
|
|
* @returns The value at the specified path, or undefined if not found
|
|
*/
|
|
export const getNestedValue = (path: string, obj: any): any => {
|
|
return path.split('.').reduce((prev, curr) => prev?.[curr], obj)
|
|
}
|