[javascript]
var studs = [{name: 'clap ', age: 15},
{name: 'martin', age: 13},
{name: 'merry', age: 10}];
function sortbyage(a, b )
{
// Sort by age from smallest to largest
return a.age > b.age;
}
function sortbyname(a, b)
{
return a.name > b.name;
}
//Sort by age
studs.sort(sortbyage);
for(var i = 0; i < ; studs.length; i )
console.log(studs[i]);
//Sort by name
studs.sort(sortbyname);
for(var i = 0 ; i < studs.length; i )
console.log(studs[i]);
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn