I am unable to access the value of the variable "k" inside the function "Success" but outside it, it's showing the correct value and also the contents of the array are not being retained inside the same function.
The value of k in the logs is always equal to the nArray.length, which is the condition for my FOR loop.
Is this a problem with Parse.com's cloud code, or is there a problem with my code?
Thanks for reading.
nArray = gameScore.get("myArray");
var query2 = new Parse.Query("User");
for (var k=1; k < nArray.length; k++) {
query2.equalTo("username", nArray[k]);
query2.find({
success: function(results) {
if (results.length !== 0) {
**alert("The value of k is" + k);** //the value of k here always is equal to the total # of loops
var object = results[0];
alert(object.id + ' - ' + object.get('email'));
var ema = object.get('email');
mArray.push(ema);
alert("Matched Contacts:" + mArray.length);
}
},
error: function() {
response.error("movie lookup failed");
}
});
alert(mArray.join('\n'));
alert("The value of k at bottom is correct" + k);
};