sortByKey(array, key, order) { return array.sort((a, b) => { let x = a[key], y = b[key] if (order) { return ((x < y) ? -1 : ((x > y) ? 1 : 0)) } else { return ((x < y) ? ((x > y) ? 1 : 0) : -1) } }) }
array是需要排序的数据,key是根据排序的参数,order是升序和降序(true是升序)
标签:return,数组,对象,key,升序,array,排序,order From: https://www.cnblogs.com/j-a-h/p/16711041.html