I have a simple for loop that I need to set up. However instead of iterating through numbers I would like to iterate through:
"A", "B", "1" and then "2"
Is there a way I can do this with just creating an inline array?
As far as I understand, you would like to replace the usage of for() loop
var i;
var array = ["A", "B", "1", "2"];
for (i = 0; i < array.length; ++i) {
alert(array[i]);
}
You can do that by simply using forEach() function
var array = ["A", "B", "1", "2"];
array.forEach(function(value) {
alert(value);
});
["A", "B", "1", "2"].forEach(...)Array.prototype.forEach.call('AB12', ...), but why?