Skip to content

Instantly share code, notes, and snippets.

@maraisr
Created June 23, 2020 04:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maraisr/7445cab689f58dfafaf066e994760597 to your computer and use it in GitHub Desktop.
Save maraisr/7445cab689f58dfafaf066e994760597 to your computer and use it in GitHub Desktop.
gets an object by path array
const getDeepByPath = <T extends unknown>(obj: T, path: readonly string[]): any => {
let i = 0;
let temp = obj;
for (; i < path.length; ++i) {
temp = temp[path[i]];
}
return temp;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment