userId = ['123', '456'];
userName = ['aaa', 'bbb'];
for (var j = 0; j < userId.length; j++) {
Instagram.otherUserMedia(userId[j], function (response) {
$('#otherInfo').append('<h2>' + userName[j] + '</h2>');
for(var i = 0; i < response.data.length; i++) {
$('#otherInfo').append('<img src="' + response.data[i].images.thumbnail.url + '" />');
}
});
}
In this code snippet, I need to show corresponding userName
with the output images from response
. But when I execute this code, value of j
increments till userId.length
and then enters the callback.
So, when I want to show the userName[j]
it says j
is undefined
because it has loop through every value in userId
.
I want to get corresponding userName
for every userId
's response
.