Is there a dictionary implementation in JavaScript?

前端 未结 10 2047
萌比男神i
萌比男神i 2020-12-12 22:04

How can I implement an array with an indexer in JavaScript? Is there something like a dictionary in .Net?

10条回答
  •  抹茶落季
    2020-12-12 22:34

    ECMAScript 6 (aka the 2015 JavaScript spec), specifies a dictionary interface, named Map. It supports arbitrary keys of any type, has a read-only size property, is not cluttered with prototypes related stuff like objects, and can be iterated over using the new for...of... construct or Map.forEach. Check the documentation on the MDN here, and the browser compatibility table here.

提交回复
热议问题