how can i return an array created in a loop javascript? -


i trying return column values database in array,but returns empty array.

function select(query, db) { var result = new array(); db.transaction(function(tx) {     tx.executesql(query, [], function(tx, rs) {         var len = rs.rows.length;          (var = 0; < len; i++) {             var row = rs.rows.item(i);             result.push({latitude : row['latitude']});         }     });  }); return result; } 

i sure array created after loop returns empty @ last.

you using asynchronous functions. so, direct return not work. need use callback.

function select(query, db, callback) {     var result = new array();     db.transaction(function(tx) {         tx.executesql(query, [], function(tx, rs) {             var len = rs.rows.length;             (var = 0; < len; i++) {                 var row = rs.rows.item(i);                 result.push({latitude : row['latitude']});             }             callback(result);         });     }); }  select(function(result) {     // result }) 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -