如果你想要返回 then 中的结果,你需要在 then 中返回一个值。这个值会被传递给下一个 then。例如:

const arr = [1, 2, 3];

Promise.resolve(arr)
  .then((arr) => {
    return arr.map((x) => x * 2);
  })
  .then((result) => {
    console.log(result); // [2, 4, 6]
    return result; // 返回结果
  })
  .then((result) => {
    console.log(result); // [2, 4, 6]
  });

在上面的例子中,map 方法返回一个新的数组,这个数组被返回到第一个 then 中,然后被传递到第二个 then 中。第二个 then 中通过返回 result 来将结果传递到下一个 then 中。

js map返回then中的结果

原文地址: https://www.cveoy.top/t/topic/gZbK 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录