首页 > 代码库 > javascript数组原生排序
javascript数组原生排序
var month = [‘January‘, ‘February‘, ‘March‘, ‘April‘, ‘May‘, ‘June‘, ‘July‘, ‘August‘, ‘September‘, ‘October ‘, ‘November‘, ‘December‘];
var list = [
{ name: ‘张三‘, age: 243, sex: 1, price: "¥3.6", month: "August", ip: "192.168.1.1" },
{ name: ‘李四‘, age: 21, sex: 0, price: "¥2.6", month: "April", ip: "192.168.2.1" },
{ name: ‘阿西吧‘, age: 29, sex: 0, price: "¥3.6", month: "June", ip: "192.168.1.233" },
{ name: ‘王五‘, age: 23, sex: 1, price: "¥3.6", month: "January", ip: "192.168.1.1" },
];
list.sort(function (i, n) {
// return month.indexOf(i.month) - month.indexOf(n.month) //月份排序
// return i.price.localeCompare(n.price);//价格排序
return i.ip.localeCompare(n.ip); //ip排序
});
console.log(list);
javascript数组原生排序