Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
First: if your keys are strings - use an object without a prototype ( ) instead - working with it is an order of magnitude faster. Object.create(null)
Map
//upd: as Dmitry Belyaev rightly noted , in modern browsers the performance of Map is not less than Object.
Second: the order of the keys in Map
corresponds to the order of addition and cannot be changed after the fact. To sort, you should get from Map
an array, sort, and either create a new one Map
from it, or re-add all the values to the original one, having previously cleared it.
If the keys are known in advance, then it is better to prepare Map
in advance with empty values - overwriting does not change the order.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question