I am trying to build an array of figure strings this API returns to me using push()
. However, when I console.log()
the figures, it shows empty but when I open them, it says 0: "figure 1" 1: "figure 2"
so they are there but how do I access them?
$(document).ready(function() {
var pixels = ['.!!Britty!!.', 'Jaguarh'];
var figures = [];
pixels.forEach(function(p) {
$.get('https://www.habbo.com/api/public/users', {
name: p
})
.done(function(response) {
figures.push(response.figureString);
});
});
console.log(figures);
$('#pixel').attr('src', 'https://www.habbo.com/habbo-imaging/avatarimage?figure=' + figures[figures.length - 1]);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<img id="pixel" />