Skip to content

Instantly share code, notes, and snippets.

@dmwyatt
Created March 23, 2021 20:29
Show Gist options
  • Select an option

  • Save dmwyatt/2f6a3ede2f093fd5c046bab59efb623b to your computer and use it in GitHub Desktop.

Select an option

Save dmwyatt/2f6a3ede2f093fd5c046bab59efb623b to your computer and use it in GitHub Desktop.
[nestedGet] Given list of strings, access nested properties in object.
/**
* Given list of stings, access nested properties in object.
*
* @param {Object<string, *>} object
* @param {Array<string>} accessors
* @returns {*}
*/
function nestedGet(object, accessors) {
return accessors.reduce((acc, prop) => {
return acc?.[prop];
}, object);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment