Converts a value into a property path array — the key segments Lodash uses for nested access. Part of Lodash Util since 4.0.0 (stable — not deprecated).
Note: It parses paths only. It does not read or write object values — pair it with _.get or _.set for that.
Syntax
Call _.toPath. Start with this line.
Lodash
_.toPath(value)
Call
What it does
_.toPath(value)
Primary signature.
_.toPath(...)
Call the util helper.
Prefer import toPath from "lodash/toPath" when you want a smaller bundle.
Library declarations
Lodash
_.toPath(value)
Parameters
Parameter
Description
value
Required. Path string, key array, or other value to convert
Shortcut. Passing the string to _.get skips an explicit toPath call.
Compatibility
Browser & Runtime Support
_.toPath is a Lodash Util helper since 4.0.0. It runs anywhere Lodash 4.x runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash.
✓ Stable · Lodash 4.0.0+
_.toPath()
Available in [email protected] full builds and the lodash/toPath modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.
100%With Lodash 4.0+
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
_.toPathLodash 4.0.0+
Bottom line: Safe for production once Lodash 4+ is loaded. Prefer import toPath from "lodash/toPath" for smaller bundles. Use it when you need an explicit key array from a path string.
Frequently Asked Questions
_.toPath(value) converts a property path into an array of keys. Official: _.toPath('a.b.c') → ['a','b','c'] and _.toPath('a[0].b.c') → ['a','0','b','c'].
No. It only parses the path. Use _.get, _.set, or _.has to access or update nested data.
split('.') ignores brackets. 'items[0].name'.split('.') yields ['items[0]','name'] — one wrong key. _.toPath splits dots and brackets correctly.
Usually no. _.get(obj, 'a.b.c') accepts a string path. Call _.toPath when you need the key array for custom logic, logging, or APIs that expect an array.
Lodash returns a new shallow copy (keys normalized). Handy when callers may pass either a string path or a pre-built key array.
No. It parses common path syntax. Allow-list or validate paths from user input before _.get or _.set.