how to use 'getOwnPropertyNames' to iterate through contents of a map

后端 未结 1 1011
深忆病人
深忆病人 2021-01-25 18:42

I have the map posted below in the code section. I added some values to the map as shown.But when i tried to display the contents of the map using \'getOwnPropertyNames\' as sh

相关标签:
1条回答
  • 2021-01-25 19:07

    A map does not have properties (which would be limited to string and symbol keys). It stores its elements on the inside. To iterate through a Map, use its entries, values, keys, or implicit iterator methods with a for … of loop:

    for (const [key, value] of mymap) {
        console.log(key, value);
    }
    
    0 讨论(0)
提交回复
热议问题