title: How to iterate through javascirpt array with a sleep/delay?
body: <p>I am trying to set  view &amp; marker at one geo location and after a delay/sleep set the marker in another location. I'm using leaflet.js. There is a data array</p>
  <pre><code>[
      {
          &quot;city&quot;: &quot;City_1&quot;,
          &quot;lat&quot;: 8.702127234287211,
          &quot;lon&quot;: 77.1684975438538,
          &quot;temp&quot;: 25,
          &quot;icon&quot;: &quot;&quot;
      },
      {
          &quot;city&quot;: &quot;City_2&quot;,
          &quot;lat&quot;: 9.083099761723636, 
          &quot;lon&quot;: 74.81806072890778, 
          &quot;temp&quot;: 0,
          &quot;icon&quot;: &quot;&quot;
      }
  ]
  </code></pre>
  <p>and on button click the data is read and looped. Tried <code>setInterval()</code> with no success.</p>
  <pre><code>const startUpdating = async () =&gt; {    
      const response = await fetch('data.json');
      const data = await response.json();
      const marker = L.marker();// init marker
  
      for (i of data) {
          // Tried setInterval(setView, 1000); // no success.
          await map.setView([i.lat, i.lon], 10);
          marker.setLatLng([i.lat, i.lon]).addTo(map);
      }
  }
  startBtn.addEventListener('click', startUpdating);
  </code></pre>
  <p>So how to set a delay so that data is read from array, set the marker and view on map, wait for some time and then again iterate.</p>