码迷,mamicode.com
首页 > 编程语言 > 详细

javascript数组原生排序

时间:2016-09-26 20:14:21      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:

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数组原生排序

标签:

原文地址:http://www.cnblogs.com/fxnet/p/5910211.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!