javascript sort进行二维数组排序
var itemlist=[]; var item={}; item['id']="1"; item['phone']=1588288163; item['time']=32133; itemlist.push(item); var item={}; item['id']="2"; item['phone']=183288163; item['time']=32132; itemlist.push(item); var item={}; item['id']="3"; item['phone']=1585828163; item['time']=32143; itemlist.push(item);
function sortNumber(a, b) { return a.time - b.time }
0: {id: "2", phone: 183288163, time: 32132} 1: {id: "1", phone: 1588288163, time: 32133} 2: {id: "3", phone: 1585828163, time: 32143}
这个回调函数就是返回值>0 需要交换 a和b 否则不交换
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/18766.html