1

I have some code that has populated a typescript dictionary.

var dictionaryOfScores: {[id: string]: number } = {};

Now that I have it I would like to sort it by the value (the number).

This dictionary could be quite large so I am hoping there is a solution to handle it in-place.

I've seen that there is a typescript-collections package that could fit my needs but I'm hoping there is a simple solution that doesn't require me to include another library.

Sort JavaScript object by key describes a plain javascript method that could be used to sort this TypeScript object, but it makes a copy, and it doesn't specifically address the TypeScript dictionary.

Naylor
  • 272
  • 2
  • 9
  • 5
    You can't sort a dictionary like you do in other languages. You will need to turn it into an array then sort it. – Elias Soares Aug 14 '19 at 15:33
  • Some suggest that https://stackoverflow.com/questions/5467129/sort-javascript-object-by-key is a duplicate question, but in addition to that question not having an accepted answer it doesn't really meet the 'Simple' or 'TypeScript' aspect of my question. Also, that question is sorting making a copy, which doesn't address my hope of sorting in place. It is possible that the correct answer to this question is 'No'. – Naylor Aug 15 '19 at 20:21

0 Answers0