First item from a Map on JavaScript ES2015

后端 未结 4 1075
眼角桃花
眼角桃花 2020-12-09 14:25

I have a Map like this:

const m = new Map();
m.set(\'key1\', {})
.
m.set(\'keyN\' {})

the Mapcan have 1 or many i

4条回答
  •  孤街浪徒
    2020-12-09 15:17

    Also, that is correct for both Set and Map: you can convert anything to Array and then get any element by its index. Something like this:

    const m = new Map();
    m.set('key1', {});
    m.set('key2', {});
    
    console.log(Array.from(m)[0]); // ['key1', {}]

提交回复
热议问题