Skip to content

Instantly share code, notes, and snippets.

@Bengejd
Created July 23, 2021 15:51
Show Gist options
  • Save Bengejd/86a79b52f8210488d032bbf551d2c88c to your computer and use it in GitHub Desktop.
Save Bengejd/86a79b52f8210488d032bbf551d2c88c to your computer and use it in GitHub Desktop.
Accessing nested JavaScript objects and arrays by string path
const resolve = (path, obj) => path.split(".").reduce((prev, curr) => prev ? prev[curr] : null, obj || self);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment