Created
March 10, 2018 10:21
-
-
Save acanimal/f0690e2434469208865c6feaa7d0bd0f to your computer and use it in GitHub Desktop.
Accessing nested object properties
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
// From: https://codeburst.io/accessing-nested-objects-in-javascript-c2ed249fe576 | |
const getNestedObject = (nestedObj, pathArr) => { | |
return pathArr.reduce((obj, key) => | |
(obj && obj[key] !== 'undefined') ? obj[key] : null, nestedObj); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment