我正在尝试构建一个数字字符串数组,该API使用push()
返回给我。但是,当我console.log()
数字时,它显示为空,但是当我打开它们时,它显示为0: "figure 1" 1: "figure 2"
,所以它们在那里,但是我该如何访问它们?
$(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" />