Created
April 4, 2023 09:06
-
-
Save zRains/ef8130004bbc2b5310e677c2ec760e3e to your computer and use it in GitHub Desktop.
Resolve value from object by given path.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function resolveData<T = any>(data: Record<string | number, any>, path: string): T { | |
const pathArr = path.split('.') | |
return path.length === 0 ? data : pathArr.reduce((originalData, path) => originalData[path], data) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment