How to initialize a Map in ES6/ES2015 similar to an Object expression?

The closest you can get is:

let object = new Map([
  ['foo', 'bar'],
  ['1', 42]
]);

Important things to notice:

  1. Object properties are identified by strings, while Map keys can be any value, so make sure all keys are strings in the input array.
  2. Iterating a Map object yields entries by insertion order. That is not guaranteed for objects, so behavior might be different.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)