我有个API调用随机返回一个电影名..。代码已经设置好了,所以它只返回一个电影名。
然后,我有第二个API调用,它在第二个axios请求中使用这个电影名来查找这个特定电影标题可用的流服务。
我的问题是,第二个API调用返回大约20个选项的数组。例如,如果我搜索“大白鲨”,它会为大白鲨、所有其他的大白鲨电影以及任何其他以大白鲨为名的电影提供结果。
我的问题是,我如何过滤这些返回信息,找到一个与正确的电影标题完美匹配,并只是显示的信息?我希望你能帮忙,并确定这将是一些过滤逻辑。谢谢!我是新的反应,所以试着学习。
const optionsParams = { method: 'GET', url: 'https://mdblist.p.rapidapi.com/', params: [], headers: { 'X-RapidAPI-Host': 'mdblist.p.rapidapi.com', 'X-RapidAPI-Key': '384177d302msh9d8e58dffccp1bfa57jsnf3cea9fef042', }, }; axios .request({ ...optionsParams, params: { s: ${movieData.title}} }) .then(function (response) { console.log(response.data); const traktid = response.data.search.traktid; const traktidOptions = { ...optionsParams, params: { t: ${traktid} };axios.request(TraktidOptions).then(功能(响应)){
const streamingServices = response.data.streams;
setStreamingState(streamingServices);
//console.log(streamingState);
console.log(response.data.streams)
let temporaryArray = [];
for (let i = 0; i < response.data.streams.length; i++){
temporaryArray.push(response.data.streams[i].name)
console.log(temporaryArray);
}
setStreamingState(streamingState => [...streamingState, `${temporaryArray}`])
if (streamingState) {
console.log(streamingState)
} else return false;
})
})`发布于 2022-05-19 18:27:02
数组方法是迭代和组织数组数据的完美工具。
在这种情况下,Array.prototype.find()将帮助您查看数组,并根据您的标准返回单个项。
例如:
const yourArray = ["jaws", "not this jaws", "definitely not jaws"];
const found = yourArray.find(arrayItem => arrayItem === "jaws");这是一个没有对象的简单示例,因此您只需根据对象属性设置条件即可。
https://stackoverflow.com/questions/72309386
复制相似问题