我想對這些數據進行排序。根據字符串長度自定義排序
我的數據是這樣的:
var test = [
{label: '41_45',
value :14},
{label: '46_50',
value :34},
{label: '1',
value :44},
{label: '10_15',
value :84}
{label: '3',
value :44},
{label: '6_10',
value :94},
{label: '16_20',
value :74},
{label: '21_25',
value :64},
{label: '26_30',
value :44},
{label: '31_35',
{label: '4',
value :44},
{label: '5',
value :24},
{label: '36_40',
value :444},
{label: '>50',
value :24},
{label: '2',
value :44}
];
但我想根據標籤進行排序,以便我能得到這樣的結果:
var test = [
{label: '1',
value :44},
{label: '2',
value :44},
{label: '3',
value :44},
{label: '4',
value :44},
{label: '5',
value :24},
{label: '6_10',
value :94},
{label: '11_15',
value :84},
{label: '16_20',
value :74},
{label: '21_25',
value :64},
{label: '26_30',
value :44},
{label: '31_35',
value :4},
{label: '36_40',
value :444},
{label: '41_45',
value :14},
{label: '46_50',
value :34},
{label: '>50',
value :24}
];
是否有任何庫或函數我可以利用來實現這一目標?
問題是我想顯示1,2,3,4,5和6-10,11-15所以基本上基於字符串的第一個字母(整數) – user3407267