I am trying to break a nested for loop inside a asynchronous call back but unable to do so:
function asyncCall(id, OnComplete) {
// id..
context.executeQueryAsync(OnSuccess, OnFailure);
function OnSuccess(sender, args) {
OnComplete(userInGroup);
}
function OnFailure(sender, args) {
console.error("Doesn't Exist!")
}
}
function callApi() {
//response from intial call
for (var key in response) {
var data = response[key];
(function (innerData) {
if (innerData) {
renderHTML(innerData);
}
})(data);
}
}
function renderHTML(data) {
for (var key in data) {
var index = data[key];
(function (innerData, id) {
asyncCall(id, function (isFound) {
if (isFound)
break; //break loop
});
})(data, index);
}
}
callApi();
I want to break the loop if the value of the property isFound is true in its response and want to achieve this in ES5 only or any work around like synchronous call might help.