B
B
Bur Ov2016-04-21 17:23:06
JavaScript
Bur Ov, 2016-04-21 17:23:06

We get friends hiding you, why does it only display the last value from the loop?

I get a list of friends from the user with id 33919072, then running through the loop, I get a list of friends from each of his friends and look for id 33919072 in it -> if I don’t find it, then I display the ID that was not found in the list id 33919072.
If there is a hopeless situation, how can you do it the right way...

var userId = 33919072;
var i = '';
var f = '';
var GetUserName = function () {
VK.api('friends.get', {'user_id' : userId}, function(data) { 
  for (i = 0, l = data.response.length; i < l; i++) { 
  var script = document.createElement('SCRIPT');
  script.src = "https://api.vk.com/method/friends.get?user_id="+ data.response[i] +"&v=5.50&callback=callbackFunc"; 
  document.getElementsByTagName("head")[0].appendChild(script); 
  f = data.response[i];
    }
  });	
  };	
function callbackFunc(result) { 
   if (result.response.items.indexOf(userId) === -1) {
    console.log(f);
  } 
}

The script successfully finds such people, but displays only the id of the last user in the console (duplicating it) prntscr.com/av0a5u
How to display the id of these users?

In js, I don’t spit at all, so I did something like that, don’t throw stones strongly .. But myself))

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question