0

I have a lodash Dictionary which looks like this: { 5: "e", 2: "b", 3: "c", 1: "a", 4: "d" } I read here and in the link attached in the answer, that typescript iteration order is guaranteed for objects. Is it also guaranteed for lodash Dictionaries? I couldn't solid information on the subject. I want to create a dropdown sorted by key in descending order, and I thought if the iteration order is guaranteed I can just use

_(myDict).reverse().value()

Is the order guaranteed? Will it work? Thanks!

Zapdor
  • 35
  • 1
  • 5
  • I don't see the word "dictionary" in [the lodash documentation](https://lodash.com/docs/4.17.15). Do you mean "object"? – T.J. Crowder Jun 01 '21 at 17:51
  • Lodash doesn't have dictionaries. What you show is a regular object. Lodash just manipulates normal data - objects, arrays, plain values, etc. Any internal data structures are pretty much never leaked to the outside. `_(myDict).reverse().value()` will most definitely unwrap the Lodash chainable and give you back the value. If `myDict` is an object (as it seems here), you'd get an object back. – VLAZ Jun 01 '21 at 17:51
  • 1
    *"and in the link attached in the answer, that typescript iteration order is guaranteed for objects"* JavaScript guarantees it, not TypeScript. Yes, there is a guaranteed order. No, using it is not a good idea. :-) The rules for it are complex. If you need order, use an array or a `Map` (the latter is maintained in order of insertion). – T.J. Crowder Jun 01 '21 at 17:52
  • Related: [Does ES6 introduce a well-defined order of enumeration for object properties?](https://stackoverflow.com/q/30076219) – VLAZ Jun 01 '21 at 17:54

0 Answers0