标签:member 技术 对象 对象数组 array 编码 bsp sort info
var member3 = [ {age: 4, name: ‘Lily3‘}, {age: 1, name: ‘Lily2‘}, {age: 10, name: ‘Lily1‘}, {age: -12, name: ‘dsjf‘}, {age: 21, name: ‘哈哈‘}, ]; console.log(member3.sort(function(a,b){ return a.age - b.age; }))
结果如下
var member3 = [ {age: 4, name: ‘Lily3‘}, {age: 1, name: ‘Lily2‘}, {age: 10, name: ‘Lily1‘}, {age: -12, name: ‘dsjf‘}, {age: 21, name: ‘哈哈‘}, ]; console.log(member3.sort(function(a,b){ return b.age - a.age; }))
结果如下
仅适用于排序标准值都为Number类型时(因为sort排序是按照编码排序的)
标签:member 技术 对象 对象数组 array 编码 bsp sort info
原文地址:https://www.cnblogs.com/LLLLily/p/10947965.html