原始数据:
let obj = {
0: '中国',
1: '上海',
2: '北京',
3: '天津',
4: '武汉'
}
转变为数组,排序:
let array = []
Object.keys(obj).forEach(key => {
array.push({
label: obj[key],
value: key
})
})
array.sort((param1, param2) => {
return param1.label.localeCompare(param2.label, 'zh')
})
console.log(array)
输出:
localeCompare 传送门 https://cloud.tencent.com/developer/section/1192182