Comment

Comment by kevincox

I would argue that all "mapping" structures should use Map these days. Objects should be used only for record/struct data with a fixed set of programmer-named keys.

I think MDN has a good comparison: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

The only real downside of maps is that they don't support JSON serialization. However you can fix this pretty easily by using a map with an overridden `toJSON` for serializable keys.

  class StringMap extends Map {
    toJSON() {
          return Object.fromEntries(this);
    }
  }
parent kevincox 3 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton