Logo

Programming-Idioms

History of Idiom 13 > diff from v17 to v18

Edit summary for version 18 by :

Version 17

2015-09-12, 14:47:36

Version 18

2015-09-13, 12:12:09

Idiom #13 Iterate over map keys and values

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

Idiom #13 Iterate over map keys and values

Print each key k 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]);
}
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.
Comments bubble
The if clause using hasOwnProperty filters out any properties that mymap may have inherited from its prototype.