我有一个要按一定值排序的2D数组,这是我的数组:
[
[
{
"Categorie": "Alimentation",
"Label": "Trsttzp",
"Prix": "45",
"Date": "01/12/2018"
}
],
[
{
"Categorie": "Alimentation",
"Label": "Trst",
"Prix": "65",
"Date": "01/13/2018"
}
],
[
{
"Categorie": "Alimentation",
"Label": "Ts",
"Prix": "99",
"Date": "01/02/2018"
}
],
[
{
"Categorie": "Alimentation",
"Label": "Ts",
"Prix": "99",
"Date": "01/12/2018"
}
],
[
{
"Categorie": "Alimentation",
"Label": "Haa",
"Prix": "55",
"Date": "01/12/2018"
}
],
[
{
"Categorie": "Alimentation",
"Label": "qsd",
"Prix": "6",
"Date": "01/12/2018"
}
]
]
我想按日期对它进行排序,我尝试使用npm中的“快速排序”库,但它似乎不起作用,我认为问题在于该库不适用于2d数组,并且我不能找到一种方法来处理打字稿或支持2d数组的库:x
答案 0 :(得分:1)
足够简单就可以做到,而无需第三方lib
let arraysorted = array.sort((x,y) => new Date(x[0].Date) > new Date(y[0].Date));