var arr = ['0.1.0', '2.2.3', '0.3003.1', '4.3', '4.3.6', '4.3.3.5']
arr.sort((a, b) => {
var items1 = a.split('.')
var items2 = b.split('.')
var k = 0
for (let i in items1) {
let a1 = items1[i]
let b1 = items2[i]
if (typeof b1 === undefined) {
k = 1
break
} else {
if (a1 === b1) {
continue
}
k = Number(a1) - Number(b1)
break
}
}
return k
})
console.log(arr) // [ '0.1.0', '0.3003.1', '2.2.3', '4.3', '4.3.3.5', '4.3.6' ]
版本号排序
最新推荐文章于 2023-10-23 21:54:49 发布