B
B
Bur Ov2016-04-21 11:04:52
JavaScript
Bur Ov, 2016-04-21 11:04:52

How to pass the value of a variable from a loop to a function (more precisely inside)?

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.

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?

If there is a hopeless situation, then how can you do these actions "correctly" ...

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