Logo

Programming-Idioms

History of Idiom 7 > diff from v70 to v71

Edit summary for version 71 by justafoo:
[JS] idiomatic js, remove unused param

Version 70

2019-09-26, 17:55:44

Version 71

2019-09-26, 18:00:39

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

Extra Keywords
traverse traversal
Extra Keywords
traverse traversal
Code
items.forEach(function(val,idx,ary){
  console.log("index=" + idx + ", value=" + val);
});
Code
items.forEach((val, idx) => {
  console.log("index=" + idx + ", value=" + val);
});
Comments bubble
This is the "functional way" of iterating.
Comments bubble
This is the functional way of iterating.