Sorting arrays in javascript by object key value

前端 未结 6 1971
迷失自我
迷失自我 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 18:00

    Use Array's sort() method, eg

    myArray.sort(function(a, b) {
        return a.distance - b.distance;
    });
    

提交回复
热议问题