JS对字符串中字符进行按自然顺序排序

使用 localeCompare() 方法来进行字符串排序

let str = "qwertyuasdfghjzxcvbn";
str = [...str].sort((a,b)=>{
    return a.localeCompare(b,"zh-CN")
}).join("")
console.log(str) //=> abcdefghjnqrstuvwxyz
posted @ 2021-08-03 13:33  Y-X南川  阅读(1094)  评论(0编辑  收藏  举报