“JJV” Kode Jawaban

JJV

var myStringArray = ["Hello","World"];
var arrayLength = myStringArray.length;
for (var i = 0; i < arrayLength; i++) {
    console.log(myStringArray[i]);
    //Do something
}
 Run code snippet
Confused Cormorant

JJV

let array = [1, 2, 3, 4, 5];
for(let index in array){
  console.log(array[index]);
}
 Run code snippet
Glamorous Goshawk

JJV

// 1: for

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

// 2: forEach

arr.forEach((v, i) => console.log(v));

// 3: for in

for (let i in arr) {
  console.log(arr[i]);
}

// 4: for of

for (const v of arr) {
  console.log(v);
}
Glamorous Goshawk

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya