javascript 数组排序

var arr=[1,2,3,5,10,4,2,19,2,0];
    alert(arr);//[1,2,3,5,10,4,2,19,2,0]
    arr.sort(function (a, b) {//升序
        return a-b;
    });
    alert(arr);//[0,1,2,2,3,4,5,10,19]

a.sort((i,j)=>{return i-j});
var arr2=[{a:1},{a:4},{a:0}]; alert(arr2.map(function (value, index, array) {//[1,4,0] return value.a; })); arr2.sort(function (a, b) {//降序 return b.a-a.a; }); alert(arr2.map(function (value, index, array) {//[4,1,0] return value.a; }));

 

posted on 2018-08-02 16:36  苹果园dog  阅读(146)  评论(0编辑  收藏  举报

导航