-4

私はこのコードを持っています

function Human(firstName,lastName,age)
{
    this.firstName = firstName;
    this.lastName =  lastName;
    this.age = age;
}

var firstHuman = new Human("Ivan","Ivanov",25);
var secondHuman = new Human("Petar","Petrov",34);
var thirdHuman = new Human("Ivailo", "Stoyanov",28);
var forthHuman = new Human("Petar", "Tudjarov",50);
var fifthHuman = new Human("Hari", "Qvorov",20);

var Humans = new Array (firstHuman,secondHuman,thirdHuman,forthHuman,fifthHuman);

配列の最初になるように、firstName でそれらを並べ替えるにはどうすればよいですか。

4

1 に答える 1

3
Humans.sort(function(a, b){return a.firstName > b.firstName});

http://jsfiddle.net/3wyBc/

于 2013-03-28T16:33:12.493 に答える