Reputation: 63
I am returning the array using a function in titanium.There are two entries in my array which are showing alert but when i access the returned value in another js file.It only show one value in alert Here is my code (it is in db.js):
function quizfun() {
var dataArray=new Array();
var quizes = db.execute('select * from Quiz');
while (quizes.isValidRow()) {
var counter = 0;
dataArray[counter] = quizes.fieldByName('Quiz_Text');
quizes.next();
alert(dataArray[counter]);//Showing two values
counter++;
};
return dataArray;
}
Here is my other js file:
quizes = db.quizfun();
alert(quizes[0]);//working
alert(quizes[1]);//alert not showing anything
Could you tell me what i am doing wrong.Thanks in advance
Upvotes: 0
Views: 435
Reputation: 7452
var counter = 0;
should be outside the while loop. Like
function quizfun() {
var dataArray=new Array();
var quizes = db.execute('select * from Quiz');
var counter = 0;
while (quizes.isValidRow()) {
dataArray[counter] = quizes.fieldByName('Quiz_Text');
quizes.next();
alert(dataArray[counter]);//Showing two values
counter++;
};
return dataArray;
}
Upvotes: 1