8 lines
319 B
TypeScript
8 lines
319 B
TypeScript
export function getNestedValue(obj: any, path: any) {
|
|
return path
|
|
.replace(/\?.\[|\]\[|\]\.?/g, ".") // Replace question mark and square brackets
|
|
.split(".") // Split by dots
|
|
.filter(Boolean) // Remove empty strings
|
|
.reduce((acc: any, key: any) => acc && acc[key], obj); // Access nested properties
|
|
}
|