使用Promise.All创建地图

发布于 2025-01-29 05:43:07 字数 399 浏览 0 评论 0原文

I have the following list = ["yellow", "blue", "red"]

我想在使用条目作为地图密钥时使用等待和PromiseAll创建一个地图,并且功能结果作为值。

例如:

async function concatStr(color): Promise<String> {
    return color + "dosomthing"
}

and the map will be:
{
  "yellow": "yellowdosomething",
  "blue": "bluedosomething",
  "red": "reddosomething"
}

我相信我需要使用产量,但不确定如何做

I have the following list = ["yellow", "blue", "red"]

I want to create a map, while with await and promiseAll while using the entries as the map key, and the function result as the value.

e.g:

async function concatStr(color): Promise<String> {
    return color + "dosomthing"
}

and the map will be:
{
  "yellow": "yellowdosomething",
  "blue": "bluedosomething",
  "red": "reddosomething"
}

I believe that I need to use yield , but not sure how to do it

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文