1let array = ['Item 1', 'Item 2', 'Item 3'];
2
3// Here's 4 different ways
4for (let index = 0; index < array.length; index++) {
5 console.log(array[index]);
6}
7
8for (let index in array) {
9 console.log(array[index]);
10}
11
12for (let value of array) {
13 console.log(value); // Will log value in array
14}
15
16array.forEach((value, index) => {
17 console.log(index); // Will log each index
18 console.log(value); // Will log each value
19});
1var myStringArray = ["hey","World"];
2var arrayLength = myStringArray.length;
3for (var i = 0; i < arrayLength; i++) {
4 console.log(myStringArray[i]);
5 //Do something
6}
1//Method 1 using for loop
2
3let array = [ 1, 2, 3, 4, 5, 6 ];
4for (let index = 0; index < array.length; index++) {
5 console.log(array[index]);
6}
7
8//Method 2 using for Of loop
9
10for (let traverse of array ){
11 console.log(traverse)
12}
1let array = [ 1, 2, 3, 4 ]; //Your array
2
3for( let element of array ) {
4 //Now element takes the value of each of the elements of the array
5 //Do your stuff, for example...
6 console.log(element);
7}