Sort array with lodash by value (integer) Sort array with lodash by value (integer) arrays arrays

Sort array with lodash by value (integer)


You can use the sortBy() function here. You don't have to specify a key, as it will fall back to identity().

var myArray = [ 3, 4, 2, 9, 4, 2 ];_.sortBy(myArray);// → [ 2, 2, 3, 4, 4, 9 ]_(myArray).sortBy().take(3).value();// → [ 2, 2, 3 ]


Selected Answer is right but we can also do that task with sort()

const _ = require('lodash');const myArray = [1,2,3,4,"A1","A10","A11","A12","A2","A3","A4","AZ","A5","B10", "B2", "F1", "F12", "F3",1,5,6,7,0,"a","b","a1"];const sortFilter = _(myArray).sort().value();console.log(sortFilter)const sortByFilter = _(myArray).sortBy().value();console.log(sortByFilter)