[javascript]
var studs = [{name: 'clap', age: 15},
{name: 'martin', age: 13},
{name: 'merry', age: 10}];
function sortbyage(a, b)
{
//按年龄从小到大排列
return a.age > b.age;
}
function sortbyname(a, b)
{
return a.name > b.name;
}
//按年龄排序
studs.sort(sortbyage);
for(var i = 0; i console.log(studs[i]);
//按姓名排序
studs.sort(sortbyname);
for(var i = 0; i console.log(studs[i]);