I am doing the following:
$.getJSON(url,function(data){
var totalQueries = data.length;
$.each(data, function(i, item) {
But this one looks like to be wrong:
var totalQueries = data.length;
As by the end of it I check for the last item and it never happens:
if (i === totalQueries - 1) {
myId = item.pageid;
console.log(myId);
newQuery();
}