Answer the question
In order to leave comments, you need to log in
Vk Api JS problem when exiting function
There is this piece of code:
function GroupMembers1(data){
GroupCount1=data.response.count;
var a=0;
for(var i=0;i<=GroupCount1; i++){
VK.api("users.get", {user_ids:data.response.users[i], fields:"sex"}, function(data){
if(data.response[0].sex==1){
GroupMember1[a]=data.response.users[i];
a++;
};
});
};
};
Answer the question
In order to leave comments, you need to log in
for(var i=0;i<=GroupCount1 - 1; i++){
Why variable a if there is already i in the loop ?
I would pass the resulting array as a parameter so that there is no doubt about where and how it is declared
function GroupMembers1(data , myReslut){
GroupCount1=data.response.count;
var a=0;
for(var i=0;i<=GroupCount1; i++){
VK.api("users.get", {user_ids:data.response.users[i], fields:"sex"}, function(data){
if(data.response[0].sex==1){
myResult[a]=data.response.users[i];
a++;
};
});
};
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question