“ITerate melalui array” 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

loop javascript melalui array

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

iterate melalui array javascript

const array = ["one", "two", "three"]
array.forEach(function (item, index) {
  console.log(item, index);
});
Wild Warbler

loop javascript melalui array

var myStringArray = ["hey","World"];
var arrayLength = myStringArray.length;
for (var i = 0; i < arrayLength; i++) {
    console.log(myStringArray[i]);
    //Do something
}
Bald Eagle

loop javascript melalui array

const array1 = ['a', 'b', 'c'];

array1.forEach(element => console.log(element));
Tame Turkey

ITerate melalui array

var arr = [1,2,3,4,5,6,7,8];

// Uses the usual "for" loop to iterate
for(var i= 0, l = arr.length; i< l; i++){
	console.log(arr[i]);
}

console.log("========================");

//Uses forEach to iterate
arr.forEach(function(item,index){
	console.log(item);
});
Creepy Gábor

Jawaban yang mirip dengan “ITerate melalui array”

Pertanyaan yang mirip dengan “ITerate melalui array”

Lebih banyak jawaban terkait untuk “ITerate melalui array” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya