Javascript自定義排序node運(yùn)行實(shí)例_javascript技巧
來源:懂視網(wǎng)
責(zé)編:小采
時(shí)間:2020-11-27 21:10:09
Javascript自定義排序node運(yùn)行實(shí)例_javascript技巧
Javascript自定義排序node運(yùn)行實(shí)例_javascript技巧:[javascript] 代碼如下:var studs = [{name: 'clap', age: 15}, {name: 'martin', age: 13}, {name: 'merry', age: 10}]; function sortbyage(a, b) { //按年齡從小到大排列 return a.age > b.age; } f
導(dǎo)讀Javascript自定義排序node運(yùn)行實(shí)例_javascript技巧:[javascript] 代碼如下:var studs = [{name: 'clap', age: 15}, {name: 'martin', age: 13}, {name: 'merry', age: 10}]; function sortbyage(a, b) { //按年齡從小到大排列 return a.age > b.age; } f
[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 < studs.length; i++)
console.log(studs[i]);
//按姓名排序
studs.sort(sortbyname);
for(var i = 0; i < studs.length; i++)
console.log(studs[i]);
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
Javascript自定義排序node運(yùn)行實(shí)例_javascript技巧
Javascript自定義排序node運(yùn)行實(shí)例_javascript技巧:[javascript] 代碼如下:var studs = [{name: 'clap', age: 15}, {name: 'martin', age: 13}, {name: 'merry', age: 10}]; function sortbyage(a, b) { //按年齡從小到大排列 return a.age > b.age; } f