In my project, I have multiple objects named stations
, each containing a property called money
.
stations[0].money = 2000
stations[1].money = 500
stations[2].money = 1200
stations[3].money = 2200
My goal is to create an array of station indexes (0, 1, 2, and 3 in this case) but arranged based on the amount of money each station has, sorted in ascending order. So the desired output should be:
var moneyArray = [1, 2, 0, 3]
I'm looking for the most elegant solution to achieve this result. Any suggestions?