📌  相关文章
📜  js 中按 AZ 对数组进行排序 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:38.602000             🧑  作者: Mango

代码示例1
// Price Low To High
array?.sort((a, b) => (a.price > b.price ? 1 : -1))
// Price High To Low
array?.sort((a, b) => (a.price > b.price ? -1 : 1))
// Name A to Z
array?.sort((a, b) => (a.name > b.name ? 1 : 1))
// Name Z to A
array?.sort((a, b) => (a.name > b.name ? -1 : 1))
// Sort by date
array.sort((a,b) =>  new Date(b.date) - new Date(a.date));