sort()排序

var ary = [8,9,10,3],

 	compare = function(a,b){

		return b.age-a.age;
 	},

	g = [

 			{
 				name:"jim",

 				age:29
 			},


 			{
				name:"tom",

 				age:15
 			},


 			{
 				name:"mary",

 				age:20
 			}

 	];


 	g.sort(compare);

 	console.log(g);

 

posted @ 2015-03-14 14:51  唸随爱  阅读(111)  评论(0编辑  收藏  举报