js--sort()排序

     var arr = [5,1,4,85,25,252];
	arr.sort(function(a,b){
		return b-a; //从大到小降序
	})
	console.log(arr)  // [252, 85, 25, 5, 4, 1]

	
	var arr = [5,1,4,85,25,252];
	arr.sort(function(a,b){
		return a-b; //从小到大升序
	})
	console.log(arr)   //[1, 4, 5, 25, 85, 252]

  

posted @ 2019-08-11 16:42  Yi只猴  阅读(115)  评论(0编辑  收藏  举报