Node.js lodash.sortBy() Function Last Updated : 29 Jun, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report Lodash is a module in Node.js that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc. The Loadsh.sortBy() function is used to sort the array in ascending order. Syntax: sortBy(collection, [iteratees=[_.identity]]) Parameters: This parameter holds the collection as a first parameter, Second parameter is optional. The second parameter is basically a function that tells how to sort. Return Value: It returns the sorted collection. Note: Please install lodash module by npm install lodash before using the below given code. Example 1: javascript let lodash = require("lodash"); let arr = [2, 1, 8, 4, 5, 8]; console.log("Before sorting: ", arr); console.log("After sorting: ", lodash.sortBy(arr)); Output: Example 2: javascript let lodash = require("lodash"); let arr = [2, 1, 5, 8, "a", "b", "10"]; console.log("Before sorting: \n" + arr); console.log("After sorting: \n" + lodash.sortBy(arr)); Output: Example 3: javascript let lodash = require("lodash"); let arr = [ {val:10, weight:100}, {val:9, weight:150}, {val:11, weight:10}, {val:1, weight:1000}, {val:74, weight:140}, {val:7, weight:100}, ]; console.log("sorted by val: \n", lodash.sortBy(arr, (e) => { return e.val })); console.log("sorted by weight: \n", lodash.sortBy(arr, (e) => { return e.weight })); Output: Comment More infoAdvertise with us Next Article Node.js lodash.sortBy() Function T tarun007 Follow Improve Article Tags : Node.js Node.js-Methods Similar Reads Node.js sort() function sort() is an array function from Node.js that is used to sort a given array. Syntax: array_name.sort() Parameter: This function does not take any parameter. Return type: The function returns the sorted array. The program below demonstrates the working of the function: Program 1: javascript function 1 min read Underscore.js _.comparator() Method The _.comparator() method takes a binary predicate-like function and returns a comparator function which can be used as a callback for the _.sort() method etc. Syntax: _.comparator( function ); Parameters:Â function: a predicate-like function defined. Return Value: This method returns a comparator f 2 min read Ember.js ArrayProxy sortBy() Method Ember.js is an open-source JavaScript framework used for developing large client-side web applications which is based on Model-View-Controller (MVC) architecture. Ember.js is one of the most widely used front-end application frameworks. It is made to speed up development and increase productivity. C 3 min read Ember.js Ember.NativeArray sortBy() Method Ember.js is an open-source JavaScript framework used for developing large client-side web applications which is based on Model-View-Controller (MVC) architecture. Ember.js is one of the most widely used front-end application frameworks. It is made to speed up development and increase productivity. C 3 min read Ember.js EmberArray sortBy() Method Ember.js is an open-source JavaScript framework used for developing large client-side web applications which is based on Model-View-Controller (MVC) architecture. Ember.js is one of the most widely used front-end application frameworks. It is made to speed up development and increase productivity. C 3 min read Like