Kode JavaScript untuk mengulangi array
var colors = ["red","blue","green"];
for (var i = 0; i < colors.length; i++) {
console.log(colors[i]);
}
Grepper
var colors = ["red","blue","green"];
for (var i = 0; i < colors.length; i++) {
console.log(colors[i]);
}
const myArray = ['foo', 'bar'];
myArray.forEach(x => console.log(x));
//or
for(let i = 0; i < myArray.length; i++) {
console.log(myArray[i]);
}
const array = ["one", "two", "three"]
array.forEach(function (item, index) {
console.log(item, index);
});
var myStringArray = ["hey","World"];
var arrayLength = myStringArray.length;
for (var i = 0; i < arrayLength; i++) {
console.log(myStringArray[i]);
//Do something
}
let exampleArray = [1,2,3,4,5]; // The array to be looped over
// Using a for loop
for(let i = 0; i < exampleArray.length; i++) {
console.log(exampleArray[i]); // 1 2 3 4 5
}
fruits.forEach(function(item, index, array) {
console.log(item, index)
})
// Apple 0
// Banana 1