Hi Asif,
Requests to Database are always asynchronous, that is the issue.
Unfortunately, we don't fully understand what your code does, do we show you the following example of work with asynchronous calls.
Asynchronous call is executed in a function, and all the needed variables are saved in a closure (find more here: https://developer.mozilla.org/en-US/d...)
prevar values = [{name:"q", age:10},{name:"w", age:10},{name:"e", age:11},{name:"r", age:11},{name:"t", age:11},{name:"y", age:12},{name:"u", age:12}];
var db = window.openDatabase("posDB", "", "posDB", 1024*1000);
db.transaction( function (tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS "menuTable"(name TEXT, age Number)');
for( var i=0; i < values.length; i++) {
tx.executeSql('INSERT INTO "menuTable" (name, age) values (?, ?)', [values.name, values.age]);
}
});
var ourFinalArray1 = {};
db.transaction(function(tx) {
function exec(i) {
tx.executeSql('SELECT * FROM "menuTable" WHERE age= ? ', , function(tx, results) {
var len = results.rows.length;
if (len 0) {
for (var j = 0; j < len; j++) { // for each row
ourFinalArray1.push(results.rows.item(j).name);
}
}
});
}
for (var i = 10 ; i < 15; i++){
ourFinalArray1 = [];
exec(i);
}
}, function(){}, function(){console.log(ourFinalArray1)});/pre
Please see console output. Hope this example will be helpful.