Sort array with lodash by value (integer)

后端 未结 2 696
暗喜
暗喜 2021-02-03 17:29

I\'m really struggling on that but I cannot find a solution.

I have an array and I want to sort it by value (all integers). I thought, well let\'s use lodash, there sure

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-03 17:59

    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)
    

提交回复
热议问题