[javascript]
var studs = [{name: 'clap ', age: 15},
{name: 'martin', age: 13},
byage(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]);