title: How to collect responses from Facebook API requests in loop?
body: <p>I am trying to collect results of FB API asynchronous requests which are called in loop. I use next code:</p>
  
  <pre><code>    function getPicturesByUserIds(friendsIdList) {
          var userPictures = [];
          for (var i = 0; i &lt; friendsIdList.length; i++) {
              (function () {
                  var userId = friendsIdList[i];
                  var j = i;
                  var friendsIdListLength = friendsIdList.length - 1;
                  FB.api('/'+userId+'/picture?type=large', function (responce) {
                      if (responce &amp;&amp; !responce.error) {
                          userPictures[userId] = responce.data.url;
                      }
                      if (j &gt;= friendsIdListLength) {
                          console.log(userPictures);
                          sendPicturesAndGetResponse(userPictures);
                      }
                  });
              })();
          }
      }
  </code></pre>
  
  <p>This code works in Chrome, but in Firefox <em>array</em> <strong>userPictures</strong> is empty.</p>