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 array = [1, 2, 3, 4, 5];
2// made an array
3
4for (var i = 0; array[i]; i++) // browse your array with this simple condition on index
5 console.log('element '+i+' = '+array[i]);
6
7//output:
8element 0 = 1
9element 1 = 2
10element 2 = 3
11element 3 = 4
12element 4 = 5
1
2
3 var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
4
5 for( var i = 0; i < arr.length; i--){
6
7 if ( arr[i] === 5) {
8
9 arr.splice(i, 1);
10 }
11
12 }
13
14 //=> [1, 2, 3, 4, 6, 7, 8, 9, 0]
15
16