我有以下数组要排序。
const input = ["12 - Blue, Red, Orange, Purple",
"16 - White, Black, Yellow, Blue, Pink",
"14 - Yellow, Brown, Grey, Maroon, Green",
"20 - Red, Black, Yellow, Peach, Aqua",
"7 - White, Cream, Grey, Green, Magenta" ]
目的是按升序对行进行排序,例如第 7 行,然后是第 12、14、16,最后是第 20。这是我试过但没有用的
const input = [
"12 - Blue, Red, Orange, Purple",
"16 - White, Black, Yellow, Blue, Pink",
"14 - Yellow, Brown, Grey, Maroon, Green",
"20 - Red, Black, Yellow, Peach, Aqua",
"7 - White, Cream, Grey, Green, Magenta"
]
var x = input.sort(function(a, b) {
return a[0] > b[0] ? 1 : -1;
});
console.log(x)
如何对这样一个复杂的数组进行升序排序?
明月笑刀无情
相关分类