Complete newbie question here. I am trying to loop through some data and ONLY run a function if I my retrieved data doesn't match items in the array. I set a boolean variable to false and was thinking to change the value of it to 'true' if a match was found. If I log my variable directly after assigning it a 'true' value, it works as expected. If I log it outside my for loop, it is back to false. Any tips for a beginner? Thanks!
var matchFound = false;
currentUserRequest.done(function (userData) {
for(var i = 0;i < arr.length;i++){
var item = arr[i];
console.log("request = " + request);
console.log("item.RequestName = " + item.RequestName);
console.log("current user = " + userData.d.Title);
console.log("item.Author[Title] = " + item.Author["Title"]);
if(request == item.RequestName && userData.d.Title == item.Author["Title"]){
matchFound = true;
//this is returning true as expected
console.log(matchFound);
}
}
});
//this is returning 'false', though I changed it to true above
console.log(matchFound);