Skip to content

Instantly share code, notes, and snippets.

@nblackburn
Last active December 7, 2024 21:08
Show Gist options
  • Save nblackburn/83d53cf170e9a8d4b6dc6862f9c7a3e3 to your computer and use it in GitHub Desktop.
Save nblackburn/83d53cf170e9a8d4b6dc6862f9c7a3e3 to your computer and use it in GitHub Desktop.
dotObj

Example

const foo = {
    bar: {
        baz: true
    }
}

dotObj('foo.bar.baz', foo); // true
const dotObj = (path, data, delimiter = '.') => {
const slices = path.split(delimiter);
return slices.reduce((a, v) => a = data[v], data);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment