0

Why is never true returned? The given name exists in the array rows and the if(rows[i].userName == name) gets triggert, but why won't this function return true?

function existUser(name){
    var Result = false;
    OOTW.MYSQL.query('SELECT * FROM Time',function(err,rows){
    if(err) throw err;
        for (var i = 0; i < rows.length; i++) {

            if (rows[i].userName == name) {

                Result = true;

            }
        }; 

    });
    console.log(Result);
    return Result;
}

1 Answers1

0

Your query executes asynchronously, long after Result is returned.

djechlin
  • 59,258
  • 35
  • 162
  • 290