Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

react iterate over map

//function which will be passed as argument to (Map.prototype.forEach())
function logMapElements(value, key, map) {
    console.log(`map.get('${key}') = ${value}`)
}
//create the map object and use forEach to loop through the keys in the map 
// and get the value associated with each value
new Map([['foo', 3], ['bar', {}], ['baz', undefined]]).forEach(logMapElements)
//Output:
// "map.get('foo') = 3"
// "map.get('bar') = [object Object]"
// "map.get('baz') = undefined"
 
PREVIOUS NEXT
Tagged: #react #iterate #map
ADD COMMENT
Topic
Name
6+9 =