6.数组排序

Javascript中提供的排序方式

针对对象数组的排序方法

var peoples = [
    { first_name: 'Lazslo', last_name: 'Jamf' },
    { first_name: 'Pig', last_name: 'Bodine' },
    { first_name: 'Pirate', last_name: 'Prentice' }
];

function Sort() {
    peoples.sort(function (a, b) {
        if (a.last_name < b.last_name) {
            return -1;
        } else if (a.last_name == b.last_name) {
            return 0;
        } else {
            return 1;
        }
    })

}
JSRUN notes