The closest you can get is:
let object = new Map([
['foo', 'bar'],
['1', 42]
]);
Important things to notice:
- Object properties are identified by strings, while Map keys can be any value, so make sure all keys are strings in the input array.
- Iterating a Map object yields entries by insertion order. That is not guaranteed for objects, so behavior might be different.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…