How to loop through a fixed (development time) list of values in JavaScript?
In Perl, I'd do:
for my $item ('foo', 'bar', 'baz') {
which would run the loop with foo, bar and baz in $item (one each loop run).
JavaScript could do:
for (item in new Array('foo', 'bar', 'baz')) {
but that would make item contain 0, 1 and 2, not the values.
Copy&paste the source for each item would be an option, but a very bad one in terms of maintenance.
Another option would be
var items = new Array('foo', 'bar', 'baz');
for (i in items) {
var item = items[i];
But that's also bad code as it defines a structure (Array) with lots of overhead where none is needed.