how to sort mixed numeric/alphanumeric array in javascript

前端 未结 4 1425
栀梦
栀梦 2021-02-09 03:25

I have a mixed array that I need to sort by number, alphabet and then by digit-

[\'A1\', \'A10\', \'A11\', \'A12\', \'A3A\', \'A3B\', \'A3\', \'A4\', \'B10\', \'         


        
4条回答
  •  滥情空心
    2021-02-09 03:51

    var a=[ {
        "LIST": "14:NATURAL RESOURCES"
    },
    {
        "LIST": "7:DIVERSITY IN LIVING ORGANISMS"
    },
    {
        "LIST": "3:ATOMS AND MOLECULES"
    },
    {
        "LIST": "10:GRAVITATION"
    },
    {
        "LIST": "6:TISSUES"
    }]
    
    var c=a.sort(function(a,b){
    let aa=a.LIST,bb=b.LIST;
    return parseInt(aa.split(":")[0] - bb.split(":")[0])
    
    })
    
    console.log(c)
    

提交回复
热议问题