Underscore _.toPath() Function Last Updated : 07 Dec, 2021 Comments Improve Suggest changes Like Article Like Report The Underscore.js _.toPath() function is used to convert the given value to a property path array.Syntax: _.toPath('key') Parameters: This method accepts a single parameter as mentioned above and described below. key: The key value that need to convert to path array. Return Value: The new property path array. Below example illustrates the _.getPath() function is Underscore.js. Example 1: HTML <!DOCTYPE html> <html> <head> <script src= "https://cdn.jsdelivr.net/npm/underscore@latest/underscore-umd-min.js"> </script> </head> <body> <script type="text/javascript"> // Use of _.toPath() method let gfg = _.toPath(['geeks', 'for', 'geeks']); // Printing the output console.log(gfg); </script> </body> </html> Output: ["geeks","for","geeks"] Example 2: HTML <!DOCTYPE html> <html> <head> <script src= "https://cdn.jsdelivr.net/npm/underscore@latest/underscore-umd-min.js"> </script> </head> <body> <script type="text/javascript"> var originalToPath = _.toPath; _.mixin({ toPath: function (path) { return _.isString(path) ? path.split('.') : originalToPath(path); } }); console.log({ a: [{ b: 5 }] }, 'a.0.b'); </script> </body> </html> Output: {"a":[{"b":5}]} a.0.b Reference: https://underscorejs.org/#toPath Comment More infoAdvertise with us Next Article Underscore _.toPath() Function S skyridetim Follow Improve Article Tags : JavaScript Web Technologies JavaScript - Underscore.js Similar Reads Underscore _.get() Function Underscore.js is a JavaScript library that provides a lot of useful functions that help in the programming in a big way like the map, filter, invokes, etc even without using any built-in objects. The _.get() function is an inbuilt function in the Underscore.js library of JavaScript which is used to 2 min read Underscore.js _.last() Function Underscore.js _.last() is used to display the last element of the array. It is usually applied to separate the elements of an array by making it into 2 arrays. One which contains only the last element and the other which contains all the elements except the last one. Syntax:_.last( array, [n] ) Para 3 min read Underscore.js _.max Function The Underscore.js is a JavaScript library that provides a lot of useful functions that help in programming in a big way like the map, filter, invokes, etc even without using any built-in objects. The _.max() function is used to find the minimum element from the list passed. If an iterate is given, t 3 min read Underscore.js _.map() Function The Underscore.js is a JavaScript library that provides a lot of useful functions that helps in the programming in a big way like the map, filter, invoke etc even without using any built-in objects. The _.map() function is an inbuilt function in Underscore.js library of the JavaScript which is used 4 min read Underscore.js _.iteratee() Function Underscore.js is a JavaScript library that provides a lot of useful functions that help in the programming in a big way like the map, filter, invoke, etc. even without using any built-in objects. The _.iteratee() function is an inbuilt function in Underscore which is used to generate a callback that 2 min read Like