The differences between index signature and a map

The differences between using a map or an index signature pattern with an object are slim. Here are two lists of the pros of each structure:

Object:

  • Can have more than just a key-value. It can have functions and other members.
  • An object coming from JSON is automatically compatible with an index signature, while a map would require a manual mapping.
  • An object pattern is faster at accessing data than the map, and uses less memory for a small set of data and a medium set of data. This is true with Chrome, but benchmarks are not consistent among browsers, as well as the overall size of the map/object.

Map:

  • A map performs better when many add and delete. It uses a hashing function underneath.
  • It preserves the order when an element is added. This might be an advantage, since a map is naturally iterable.
  • A map performs better with a large set of data.
  • A map's key is not limited to a number or a string for a key.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.146.176.88