What I'm trying to do is build an array from a JSON response. I'm not sure what I'm doing wrong. The array is somehow built but I can't access the elements like active_team_members[0];
Any idea on what I'm doing wrong?
Thanks.
var active_team_members = getJsonUsers();
console.log(active_team_members[0]); // this returns "undefined"
var x_active_team_members = [1,2,3,4,5];
console.log(x_active_team_members[0]); // this works
console.log(active_team_members); //returns some kind of array? If you check your browser console you can see the array but it differs from the one below
console.log(x_active_team_members); //this is a normal array
function getJsonUsers() {
var members = [];
$.getJSON( "http://www.json-generator.com/api/json/get/bZjdjoFLvS?indent=2", function( data ) {
$.each( data, function( key, val ) {
$.each( val, function( k, v ) {
members.push(parseInt(v.user.uid));
});
});
});
return members;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>