Created
March 4, 2023 22:15
-
-
Save Git-I985/b1bad7d18dab10cdf3bec680efefd466 to your computer and use it in GitHub Desktop.
JS nested object access
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
const get = (obj, keys) => | |
!Object.hasOwn(obj, keys[0]) | |
? null | |
: keys.length === 1 | |
? obj[keys[0]] | |
: get(obj[keys[0]], keys.slice(1)); | |
export default get |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment