The Lodash _.toPath() method is used to convert the given value to a property path array.
Syntax:
_.toPath(value)
Parameters: This method accepts a single parameter as mentioned above and described below:
- value: The value that need to convert to path array.
Return Value: The new property path array.
Example 1:
Javascript
// Requiring the lodash library const _ = require( "lodash" ); // Use of _.toPath() method let gfg = _.toPath( 'neveropen.for.neveropen' ); // Printing the output console.log(gfg); |
Output:
["neveropen", "for", "neveropen"]
Example 2:
Javascript
// Requiring the lodash library const _ = require( "lodash" ); // Use of _.toPath() method let gfg = _.toPath( 'neveropen[0].for[1].neveropen[2]' ); // Printing the output console.log(gfg); |
Output:
["neveropen", "0", "for", "1", "neveropen", "2"]