Skip to content

Instantly share code, notes, and snippets.

@zRains
Created April 4, 2023 09:06
Show Gist options
  • Save zRains/ef8130004bbc2b5310e677c2ec760e3e to your computer and use it in GitHub Desktop.
Save zRains/ef8130004bbc2b5310e677c2ec760e3e to your computer and use it in GitHub Desktop.
Resolve value from object by given path.
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