1var colors=["red","blue","green"];
2for (let i = 0; i < colors.length; i++) {
3 console.log(colors[i]);
4}
1let array = ['Item 1', 'Item 2', 'Item 3'];
2
3array.forEach(item => {
4 console.log(item); // Logs each 'Item #'
5});
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 each 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 listItem = [
2 {name: 'myName1', gender: 'male'},
3 {name: 'myName2', gender: 'female'},
4 {name: 'myName3', gender: 'male'},
5 {name: 'myName4', gender: 'female'},
6 ]
7
8 for (const iterator of listItem) {
9 console.log(iterator.name+ ' and '+ iterator.gender);
10 }
1<body>
2
3<h2>Automatic Slideshow</h2>
4<p>Change image every 5 seconds:</p>
5
6
7<div class="slideshow-container">
8 <div class="mySlides fade">
9 <img src="img_nature_wide.jpg" style="width:100%">
10 </div>
11
12 <div class="mySlides fade">
13 <img src="img_snow_wide.jpg" style="width:100%">
14 </div>
15
16 <div class="mySlides fade">
17 <img src="img_mountains_wide.jpg" style="width:100%">
18 </div>
19</div>
20
21<br>
22
23
24
25<div class="row">
26 <div class="column">
27 <img id="myBtn" class="demo cursor stop_loop" src="img_woods.jpg" style="width:100%" onclick="currentSlide(0); breakLoop();">
28 </div>
29
30 <div class="column">
31 <img id="myBtn" class="demo cursor stop_loop" src="img_5terre.jpg" style="width:100%" onclick="currentSlide(1)">
32 </div>
33
34 <div class="column">
35 <img id="myBtn" class="demo cursor stop_loop" src="img_mountains.jpg" style="width:100%" onclick="currentSlide(2)">
36 </div>
37</div>
38
39
40
41
42
43<script>
44var slideIndex = 0; //indica che parto dall'immagine n.1
45showSlides();
46
47
48// script per lo slide delle immagini al click
49function plusSlides(n) {
50 showSlides(slideIndex += n);
51}
52
53function currentSlide(n) {
54 showSlides(slideIndex = n);
55}
56
57
58// funzione per mostrare le slides
59function showSlides() {
60 var i;
61 var slides = document.getElementsByClassName("mySlides");
62 var dots = document.getElementsByClassName("demo");
63 var exitLoop = 0; //interrompere il loop al click delle immagini
64
65 for (i = 0; i < slides.length; i++) {
66 slides[i].style.display = "none";
67 }
68 slideIndex++;
69
70 if (slideIndex > slides.length) {slideIndex = 1}
71 for (i = 0; i < dots.length; i++) {
72 dots[i].className = dots[i].className.replace(" active", "");
73 }
74
75 slides[slideIndex-1].style.display = "block";
76 dots[slideIndex-1].className += " active";
77
78
79
80 enter code here
81
82 if(exitLoop == 0) {
83 setTimeout(showSlides, 5000); // Change image every 5 seconds
84 }
85
86}
87</script>
88
89</body>
90</html>