Sorting arrays in javascript by object key value

前端 未结 6 1973
迷失自我
迷失自我 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:52

    Here's the same as the current top answer, but in an ES6 one-liner:

    myArray.sort((a, b) => a.distance - b.distance);

提交回复
热议问题