Logo

Programming-Idioms

History of Idiom 7 > diff from v2 to v3

Edit summary for version 3 by :

Version 2

2015-07-31, 19:16:50

Version 3

2015-08-01, 16:46:51

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Code
// Functional version
items.forEach(function(val,idx,ary){ console.log("index="+idx+", value="+val) });

// Iterative version
for (var i in items) {
   console.log("index="+i+", value="+items[i]);
}