0

Say I had an array like this:

[{"Platinum":13},{"Bronze":2910},{"Diamond":92},{"Gold":346},{"Silver":649},{"Stone":12561}]

How would I be able to sort them so they organize themselves from largest to smallest by the number:

[{"Stone":12561},{"Bronze":2910},{"Silver":649},{"Gold":346},{"Bronze":2910},{"Diamond":92},{"Platinum":13}]

Any answer is appreciated, I'm completely stuck on this.

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Arcerion
  • 11
  • 2

1 Answers1

2

let arr = [{"Platinum":13},{"Bronze":2910},{"Diamond":92},{"Gold":346},{"Silver":649},{"Stone":12561}]

arr.sort((a,b) => Object.values(b)[0] - Object.values(a)[0])

console.log(arr)
Alan Omar
  • 4,023
  • 1
  • 9
  • 20