Logo

Programming-Idioms

History of Idiom 13 > diff from v60 to v61

Edit summary for version 61 by justafoo:
[JS] remove obsolete comment

Version 60

2019-09-26, 17:43:30

Version 61

2019-09-26, 17:43:55

Idiom #13 Iterate over map keys and values

Print each key k with its value x from an associative array mymap

Illustration

Idiom #13 Iterate over map keys and values

Print each key k with its value x from an associative array mymap

Illustration
Extra Keywords
table dictionary hash traverse traversal
Extra Keywords
table dictionary hash traverse traversal
Code
Object.entries(mymap).forEach(([key, value]) => {
	console.log('key:', key, 'value:', value);
});
Code
Object.entries(mymap).forEach(([key, value]) => {
	console.log('key:', key, 'value:', value);
});
Comments bubble
The if clause using hasOwnProperty filters out any properties that mymap may have inherited from its prototype.