Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/471.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Promise.fetch之前的所有返回都已解决_Javascript_Promise - Fatal编程技术网

Javascript Promise.fetch之前的所有返回都已解决

Javascript Promise.fetch之前的所有返回都已解决,javascript,promise,Javascript,Promise,有了口袋妖怪ID数组,我希望通过从口袋妖怪API获取一个口袋妖怪对象数组。我们的目标是从中获益 [1,2,3] 为此: [ {name: "ivysaur", weight: 130, …}, {name: "venusaur", weight: 1000, …}, {name: "bulbasaur", weight: 69, …} ] 我花了很长时间仔细研究了这个线程,但没有一个解决方案对我有效。我也有同样的问题,但提出的解决方案仍然没有产生结果 我的承诺。所有的都是用一个未

有了口袋妖怪ID数组,我希望通过从口袋妖怪API获取一个口袋妖怪对象数组。我们的目标是从中获益

[1,2,3]
为此:

[
  {name: "ivysaur", weight: 130, …},
  {name: "venusaur", weight: 1000, …},
  {name: "bulbasaur", weight: 69, …}
]
我花了很长时间仔细研究了这个线程,但没有一个解决方案对我有效。我也有同样的问题,但提出的解决方案仍然没有产生结果

我的
承诺。所有的
都是用一个
未定义的
数组来实现的,而不是口袋妖怪。为什么?

const pokemonIds=[1,2,3]
const pokemons=pokemonIds.map(id=>{
取回(`https://pokeapi.co/api/v2/pokemon/${id}`)
.then(res=>res.json())
。然后(json=>{
console.log(json)
返回json
})
})
Promise.all(口袋妖怪)。然后(res=>{
log('pokemon arr:',res)

})
提取之前,您缺少返回:

const pokemons = pokemonIds.map(id => {
    return fetch(`https://pokeapi.co/api/v2/pokemon/${id}`)
    .then(res => res.json())
        .then(json => {
          console.log(json)
          return json
    })
});
或:


在fetchahhhh之前添加一个返回,该死,就是这样-_-"
const pokemons = pokemonIds.map(id => 
    fetch(`https://pokeapi.co/api/v2/pokemon/${id}`)
    .then(res => res.json())
        .then(json => {
          console.log(json)
          return json
    })
)