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});
1let array = ["loop", "this", "array"]; // input array variable
2for (let i = 0; i < array.length; i++) { // iteration over input
3 console.log(array[i]); // logs the elements from the current input
4}
1function test() {
2 var sub_array = [];
3 var super_array = [];
4 for (var i = 1; i <= 3; i++) {
5 sub_array.push(i);
6 super_array.push(sub_array.slice(0));
7 }
8 alert(super_array);
9}