Skip to content

Instantly share code, notes, and snippets.

@acanimal
Created March 10, 2018 10:21
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 acanimal/f0690e2434469208865c6feaa7d0bd0f to your computer and use it in GitHub Desktop.
Save acanimal/f0690e2434469208865c6feaa7d0bd0f to your computer and use it in GitHub Desktop.
Accessing nested object properties
// 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