Does JavaScript have a Map literal notation?

前端 未结 3 1875
时光说笑
时光说笑 2020-12-16 08:56

As of ES6, JavaScript has a proper Map object. I don\'t see a way to use a literal notation though, as you could with an Array or an Object. Am I missing it, or does it not

3条回答
  •  爱一瞬间的悲伤
    2020-12-16 09:38

    There is a way to do it, like we do with literals

    const fruits = new Map(Object.entries({apples: 1, bananas: 2}))

提交回复
热议问题