I think this is what you meant:
$(document).ready(function() {
var questions = [];
$.getJSON("http://localhost:8080/audioMillionaire/test2.php", function(result) {
$.each(result, function(i, item) {
questions.push([result[i].qid, result[i].description, result[i].a]);
});
});
});
If not, please comment.
Edit: BenM was faster
Edit:
This works as well, but I cannot use the array outside of $.getJSON
This is because you are probably using code like this:
...
questions.push([result[i].qid, result[i].description, result[i].a]);
});
});
console.log(questions);
Because javascript is an asynchronous language the console log call happens before the pushes after the json was requested. You can read more about it here.
$(document).ready(function() {
console.log("set test to old");
var test = "old";
setTimeout(function() {
console.log("set test to new");
test = "new";
console.log("inside timeout: " + test);
}, 3000); // runs in 3 seconds
console.log("outside timeout: " + test);
});
This code should provide a good example. The function setTimeout just waits 3 seconds and runs the function (much like the json request).
Knowing this you should find a solution on your own (like calling a passed function after the array has been pushed). If not comment.
Edit: changed link to other, better page.
questionJis a string. Please show us yoursetArray()function.