var arr = ['0.1.1', '2.3.3', '0.3002.1', '4.2', '4.3.5', '4.3.4.5'] arr.sort((a,b)=>{ var items1 = a.split('.') var items2 = b.split('.') var len = Math.max(items1.length, items2.length) var k = 0 for (let i = 0; i < len; i++) { let a1 = items1[i] let b1 = items2[i] if (typeof a1 === 'undefined') { k = -1 break } else if (typeof b1 === 'undefined') { k = 1 break } else { if (a1 === b1) { continue } k = Number(a1) - Number(b1) break } } return k }) console.log(arr)