【发布时间】:2021-05-09 22:38:14
【问题描述】:
const search = await spot.search(request, {
limit: 3,
type: ['track']
});
search.tracks.items.forEach(song => {
let tableArtists = []
song.artists.forEach(artist => {
if (song.artists[0].name == artist.name) return tableArtists.push(artist.name)
if (song.artists[song.artists.length].name == artist.name) return tableArtists.push(" & " + artist.name)
tableArtists.push(", " + artist.name)
})
console.log(song.name + " - " + tableArtists.join(" "))
})
这个代码应该得到一首歌曲中的所有艺术家,最后一个以&符号开头。目前,它不会得到最后一位艺术家的名字。为什么?仅供参考:song.artists.last() 也不起作用。
【问题讨论】:
-
请提供来自
search的数据样本和minimal reproducible example 的预期结果
标签: javascript node.js