按照数组中的对象属性进行排序

按照数组中的对象属性进行比较排序


**方法一: **

var arry = [{value:6,url:'xxx.html'},{value:3,url:'aaa.html'},{value:9,url:'bbb.html'}]
         function compare(property) { //按照数组中的对象属性进行排序
            return function (a, b) {
              var value1 = a[property];
              var value2 = b[property];
              return value1 - value2;
            }
          }

         arry.sort(compare('value'))

方法二:
没时间写了,我要去健身房了

posted @ 2018-12-19 18:56  可乐雪碧芬达  阅读(1004)  评论(0编辑  收藏  举报