Created
June 23, 2020 04:41
-
-
Save maraisr/7445cab689f58dfafaf066e994760597 to your computer and use it in GitHub Desktop.
gets an object by path array
This file contains hidden or 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
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