Here is an array containing multiple objects without any keys:
const result = [
["Joe", "1", "2.22%", "$3,000.00"],
["Tom", "1", "2.22%", "$4,650.00"],
["Ryan", "4", "4.44%", "$18,925.00"],
["Jordan", "2", "4.44%", "$3,300.00"],
["Fred", "0", "0.00%", "$0.00"],
["Steve", "0", "0.00%", "$0.00"]
]
I'm having difficulty trying to sort the array by the fourth object. Is there a simple way to achieve this sorting without modifying the original array?
The desired outcome is to return the sorted results in descending order based on the fourth object.
return {result: result[2][0] + ": " + result[2][3] + '\n' + result[1][0] + ': ' + result[1][3] + '\n' + result[3][0] + ': ' + result[3][3] + '\n' + result[0][0] + ': ' + result[0][3] + '\n' + result[4][0] + ': ' + result[4][3] + '\n' + result[5][0] + ': ' + result[5][3] };
The returned results will appear as follows:
Ryan: $18,925.00
Tom: $4,650.00
Jordan: $3,300.00
Joe: $3,000.00
Fred:$0.00
Steve: $0.00