<script>
var arr = [
{ name: 'zopp', id: 0 },
{ name: 'gpp', id: 18 },
{ name: 'yjj', id: 8 }
];
function compare(property) {
return function (a, b) {
var value1 = a[property];
var value2 = b[property];
return value1 - value2;
}
}
console.log(arr.sort(compare('age')))
</script>
给其中的某个特殊值做变化就行