如何在JavaScript中替换一部分字符串并等待任务完成,然后继续使用其余代码

发布于 2025-01-21 15:05:35 字数 372 浏览 1 评论 0原文

let searchKeyword = 'hi'
Array[lastIndex]= await Array[lastIndex].replace(searchKeyword,'user_id:12345,"email":mail') /*wait for this line of code to finish executing, before continuing on with rest of code */
logger.info('hi')

我是否必须使用诺言,我尝试使用等待,但它说等待对这种表达没有影响。我有更多的代码,但这只是我要实现的基本思想,我仍然有异步编程并了解等待和承诺是新的。

let searchKeyword = 'hi'
Array[lastIndex]= await Array[lastIndex].replace(searchKeyword,'user_id:12345,"email":mail') /*wait for this line of code to finish executing, before continuing on with rest of code */
logger.info('hi')

do i have to use promises, I tried using await but it says await has no affect on this type of expression. i have more code but this is just the basic idea I am trying to accomplish, I am still new with asynchronous programming and learn about await and promises

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

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

发布评论

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