I had this this function and what it does to fetch value from network response and I manage to display the output 0: {recipeName: value_1} and 1: {recipeName: value_2}. 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?
function (e) {
var returnedData = JSON.parse(e.responseText);
console.log(returnedData);
if(returnedData.length != 0){
for (var x=0; x < returnedData.length; x++ ){
var listOfRecipe = '('+[x]+') ' + returnedData[x]['recipeName'];
}
alert("Recipe cannot be deactivated, it is used in the following sub recipes: " + listOfRecipe);
}
}
Current output
Recipe cannot be deactivated, it is used in the following sub recipes: (1) value_2
What I want
Recipe cannot be deactivated, it is used in the following sub recipes: (0) value_1 (1) value_2