Logo

Programming-Idioms

History of Idiom 13 > diff from v2 to v3

Edit summary for version 3 by :

Version 2

2015-07-31, 19:38:54

Version 3

2015-08-01, 17:22:56

Idiom #13 Iterate over map keys and values

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

Idiom #13 Iterate over map keys and values

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

Code
for (k in mymap) {
   if (mymap.hasOwnProperty(k))
      console.log("key="+k+", value="+mymap[k]);
}
Comments bubble
The if statement using hasOwnProperty filters out any properties that mymap may have inherited from its prototype.