本地编辑数组或者ajax后台拿回来的数组,想根据数组对象里的某个属性重新排序数组对象,如下例子: var result = [ {age:'20',name:'tim'}, {age:'18',name:'ycon'}, {age:'21',name:'yext'} ];// function compare(property){ return function(a,b){ var value1 = a[property]; var value2 = b[property]; return value1 - value2; } } result.sort(compare("age"));
转载于:https://my.oschina.net/yext/blog/786404