Logo

Programming-Idioms

History of Idiom 7 > diff from v35 to v36

Edit summary for version 36 by :
[JS] Alternative impl -> created new impl 1267

Version 35

2016-02-03, 16:43:46

Version 36

2016-02-03, 16:45:28

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]);
}
Code
items.forEach(function(val,idx,ary){
  console.log("index=" + idx + ", value=" + val);
});
Comments bubble
This is the "functional way" of iterating.