title: Getting value outside for loop
body: <p>I need to get values of Z variable outside a <code>for</code> but when I print it in the console from inside the loop it gives correct values, while I printing it from outside the loop, it gives one value of value that supposed to be returned</p>
  
  <pre><code>fetch('http://open.mapquestapi.com/elevation/v1/profile?key=tHXSNAGXRx6LAoBNdgjjLycOhGqJalg7&amp;shapeFormat=raw&amp;latLngCollection='+profile)
            .then(r =&gt; r.json()) 
            .then(data =&gt; {
              var Z;
              for(var i=0;i&lt;data.elevationProfile.length;i++){
                  //console.log(data.elevationProfile[i].height);
                  Z = (data.elevationProfile[i].height);
                  //console.log(Z);
                  }
                  console.log(Z);
  </code></pre>