Logo

Programming-Idioms

History of Idiom 7 > diff from v71 to v72

Edit summary for version 72 by justafoo:
[JS] comment

Version 71

2019-09-26, 18:00:39

Version 72

2019-09-26, 18:01:57

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
for (var i in items) {
   console.log("index=" + i + ", value=" + items[i]);
}
Code
for (var i in items) {
   console.log("index=" + i + ", value=" + items[i]);
}
Comments bubble
this is a horrible implementation, use the "functional" one above. If you don't need the index, using "for...of" is ok, "for...in" almost never is.