let listData=[{id:1,name:"测试1",presenttime:1557883600000},{id:2,name:"测试2",presenttime:1580751813000},{id:
3,presenttime:1561448381000}];
console.log("排序前:",listData);
//根据时间进行排序
listData = listData.sort(compare("presenttime"));
console.log("排序后:",listData);
//对数组进行排序
function compare(property) {
return (firstobj, secondobj) => {
const firstValue = firstobj[property];
const secondValue = secondobj[property];
return firstValue - secondValue; //升序
};
}
js 对数组对象进行排序
最新推荐文章于 2024-09-03 21:44:01 发布