๐Map
๐ง under construction
breadcrumb ๐ง
้็ถ Object ่ Map ้ฝๆฏ JS ็จไพๅฏฆ็พ Dictionary ็ๆนๆณ๏ผไฝๅฎๅๅญๅจๅบๆฌ็ไธๅ้ปใ
Maps vs. Objects
feature
Map
Object
โ use [...map] to convert into Array.
โ for(const [key, value] of map){...}
โ for(const key of map.keys()){...}
โ for(const value of map.values()){...}
โ map.forEach((value, key) => {...})
โ does not implement iteration protocol.
โ not directly iterable using for...of.
โญ can use for...in to iterate over enumerable properties.
keys
can be any value (including functions, objects, or any primitive).
Map โ Array
// Array => Map
const map = new Map([['key1', 'value1'], ['key2', 'value2']])
// Map => Array<[Key, Value]>
[...map] // [['key1', 'value1'], ['key2', 'value2']]
// Map => Array<Value>
[...map.values()]
Other Topics
Last updated
Was this helpful?