-1

I have this function, i need to store some values in an array, i need t create an array variable and store them here.

I have this function :

function loadFriends()
{
    //get array of friends
    FB.api('/me/friends?fields=name,first_name,gender', function(response) {
        console.log(response);
        var divContainer=$('.facebook-friends');
        var testdiv = document.getElementById("test");

for(var i=0; i<response.data.length; i++){
    if(response.data[i].gender == 'male'){
         testdiv.innerHTML += response.data[i].id + '<br />';
    }
}

I need to store all values of response.data[i].id in an array, as an array.. i need something like var array = [1,2,3,4] where 1,2,3,4 are the response.data[i].id ...

4

1 回答 1

3

我需要将 response.data[i].id 的所有值存储在一个数组中

使用push

var  arr = []; // Creates an empty array literal.

for(var i = 0; i < response.data.length; i++){
        arr.push(response.data[i].id);
}

push在 MDN 网站上阅读

于 2012-05-28T08:08:53.977 回答