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 each value
14}
15
16array.forEach((value, index) => {
17 console.log(index); // Will log each index
18 console.log(value); // Will log each value
19});
1array = [ 1, 2, 3, 4, 5, 6 ];
2for (index = 0; index < array.length; index++) {
3 console.log(array[index]);
4}
1array = [ 1, 2, 3, 4, 5, 6 ];
2 //set variable//set the stop count // increment each loop
3for (let i = 0; i < array.length ;i++) {
4
5 array[i] //iterate through each index.
6 //add the intructions you would like to perform.
7
8 // add any method to array[
9}
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}