sort object dictionary javscript 1

sort object dictionary javscript

arr.sort((x, y) => x.distance - y.distance);

Here is what the above code is Doing:
1. We’re creating a new array called sortedArr.
2. We’re using the sort() method to sort the array.
3. We’re using the arrow function to compare the distance of each object.
4. We’re returning the sorted array.

Similar Posts