title: Javascript fetch value from network response
body: <p>I had this this function and what it does to fetch value from network response and I manage to display the output <code>0: {recipeName: value_1}</code> and <code>1: {recipeName: value_2}</code>. But now the problem I want to display the result together with an alert message. Any idea how to make alert message display only once but the result display in loop?</p>
  
  
  
  <pre class="lang-js prettyprint-override"><code>function (e) {
    var returnedData = JSON.parse(e.responseText);
    console.log(returnedData);
  
    if(returnedData.length != 0){
      for (var x=0; x &lt; returnedData.length; x++ ){
        var listOfRecipe = '('+[x]+') ' + returnedData[x]['recipeName'];
      }
      alert("Recipe cannot be deactivated, it is used in the following sub recipes: " + listOfRecipe);
    }
  }
  </code></pre>
  
  <p>Current output</p>
  
  <blockquote>
    <p>Recipe cannot be deactivated, it is used in the following sub recipes:
    (1) value_2</p>
  </blockquote>
  
  <p>What I want</p>
  
  <blockquote>
    <p>Recipe cannot be deactivated, it is used in the following sub recipes:
    (0) value_1 (1) value_2</p>
  </blockquote>