loop to array javascript code example
Example 1: javascript code to loop through array
var colors = ["red","blue","green"];
for (var i = 0; i < colors.length; i++) {
console.log(colors[i]);
}
Example 2: putting a loop into an array javascript
function test() {
var sub_array = [];
var super_array = [];
for (var i = 1; i <= 3; i++) {
sub_array.push(i);
super_array.push(sub_array.slice(0));
}
alert(super_array);
}
Example 3: javascript iterate array
String[] myStringArray = {"Hello", "World"};
for (String s : myStringArray)
{
}