“iterate melalui array js” Kode Jawaban

Kode JavaScript untuk mengulangi array

var colors = ["red","blue","green"];
for (var i = 0; i < colors.length; i++) {
    console.log(colors[i]);
}
Grepper

iterate melalui array js

var arr = ["f", "o", "o", "b", "a", "r"]; 
for(var i in arr){
	console.log(arr[i]);
}
FlashingMustard

loop javascript melalui array

var colors = ["red","blue","green"];
colors.forEach(function(color) {
  console.log(color);
});
Gifted Gerenuk

JavaScript iterate array

var txt = "";
var numbers = [45, 4, 9, 16, 25];

numbers.forEach(function(value, index, array) {
  txt = txt + value + "<br>";
});
Pleasant Platypus

loop javascript melalui array

const myArray = ['foo', 'bar'];

myArray.forEach(x => console.log(x));

//or

for(let i = 0; i < myArray.length; i++) {
  console.log(myArray[i]);
}
MrGeeDee

loop javascript melalui array

let array = ['Item 1', 'Item 2', 'Item 3'];

for (let item of array) {
  console.log(item);
}
garzj

Jawaban yang mirip dengan “iterate melalui array js”

Pertanyaan yang mirip dengan “iterate melalui array js”

Lebih banyak jawaban terkait untuk “iterate melalui array js” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya