如何在JavaScript中替换一部分字符串并等待任务完成,然后继续使用其余代码
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论