Languages
[Edit]
EN

JavaScript - convert object to Map

6 points
Created by:
James-Z
767

In this article, we would like to show you how to convert object to Map in JavaScript.

ES8+ solution

Edit

In this section, we present solution using Object.entries().

Note:

Object.entries() was introduced in ECMAScript 2017 (ES8).

 

Alternative solution (older JavaScript)

Edit

In the example below, we get object keys using keys() method, then we iterate over the keys and add entries to a Map object using set() method.

 

See also

Edit
  1. JavaScript - convert Map to object

References

Edit
  1. Object.keys() - JavaScript | MDN
  2. Map.prototype.set() - JavaScript | MDN
  3. Map.prototype.get() - JavaScript | MDN

Alternative titles

  1. JavaScript - object to Map conversion
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join