Sorting arrays in javascript by object key value

前端 未结 6 1972
迷失自我
迷失自我 2020-12-04 17:44

How would you sort this array with these objects by distance. So that you have the objects sorted from smallest distance to biggest distance ?

Object { dista         


        
6条回答
  •  情书的邮戳
    2020-12-04 17:54

    This worked for me

    var files=data.Contents;
              files = files.sort(function(a,b){
            return a.LastModified - b. LastModified;
          });
    

    OR use Lodash to sort the array

    files = _.orderBy(files,'LastModified','asc');
    

提交回复
热议问题