sort排序 数组里面 对象根据某一字段sort排序
作者:互联网
var arr = [ {name:'zopp',age:0}, {name:'gpp',age:18}, {name:'yjj',age:8} ]; function compare(用于判断的属性名){ return function(a,b){ var value1 = a[用于判断的属性名]; var value2 = b[用于判断的属性名]; return value1 - value2; } } console.log(arr.sort(compare('age'))) //返回对象,age从小到大正向
原文 https://blog.csdn.net/a546598185/article/details/80140374
标签:sort,function,arr,某一字,name,age,var,排序 来源: https://www.cnblogs.com/suanmei/p/11195893.html