在JavaScript中,console.log给出了for循环的每个值.但是var.text只显示最后一个值.这是为什
In JavaScript console.log gives me every value from a for loop. However var.text only displays the last value. Why is this?
所以我使用Music Graph API来访问和显示与当前艺术家相似的艺术家(在本例中为" the Who.")。然而,当我使用for循环来遍历结果时,.text(artistNames)只打印数组中的姓氏(在这种情况下,它只打印Pink Floyd,即使数组包含更多的艺术家)。但是,console.log打印数组中的每个名称。我如何得到。text打印数组中的每个名字?
下面是我的代码:
JavaScript
for (i = 0; i < response.data.length; i++) {
var artistNames = response.data[i].name;
$('#relatedArtists').text(artistNames);
console.log(artistNames);
}