我正在尝试将多个剧集ID作为参数,并从json数据中显示该剧集的信息。 我已将episodeArray中的所有剧集信息推送完毕 但是显示它时,两个参数显示输出数组两次。 我如何只展示一次?
JAVACRIPT CODE
我的代码是:
let episodeData = bigEpisodeData._embedded.episodes
let searchEpisode = (...epiId) => {
let episodeArray = new Array()
for (currId of epiId){
for (currentEpisode of episodeData) {
let epiInfo = currentEpisode
if (epiInfo.id === currId) {
episodeArray.push(epiInfo)
console.log(episodeArray)
}
}
}
}
searchEpisode(3061, 3062)
答案 0 :(得分:0)
您需要将console.log
移到循环之外
let searchEpisode = (...epiId) => {
let episodeArray = new Array()
for (currId of epiId) {
for (currentEpisode of episodeData) {
let epiInfo = currentEpisode
if (epiInfo.id === currId) {
episodeArray.push(epiInfo)
}
}
}
console.log(episodeArray)
}