localeCompare()
//Demo
const workers = [
{
name: '張鐵柱',
tel: '18233339999'
},
{
name: '阿龍',
tel: '18233339999'
},
{
name: '王師傅',
tel: '18233339999'
}
];
const result = workers.sort(function (a, b) {
return a.name.localeCompare(b.name);
});
window.console.log(JSON.stringify(result));
//結(jié)果
[
{"name":"阿龍","tel":"18233339999"},
{"name":"王師傅","tel":"18233339999"},
{"name":"張鐵柱","tel":"18233339999"}
]