Logo

Programming-Idioms

History of Idiom 7 > diff from v89 to v90

Edit summary for version 90 by programming-idioms.org:
[JS] +DocURL

Version 89

2020-08-11, 14:30:33

Version 90

2020-09-02, 10:45:42

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

Variables
i,x,items
Variables
i,x,items
Extra Keywords
traverse traversal
Extra Keywords
traverse traversal
Code
items.forEach((val, idx) => {
  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.
Doc URL
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach