如何跳过“第一条消息”或从第n行启动异步功能?
async function oneByOne() {
await talk("First Message");
await talk("Second Message?");
await talk("Last Message?");
}
答案 0 :(得分:2)
拥有一系列消息并遍历它们
async function oneByOne(startIndex) {
const messages = ["first message", "second message?", "last message?"];
while (startIndex < messages.length) {
await talk(messages[startIndex]);
startIndex++;
}
}
现在,您可以输入oneByOne
的索引了。如果您说oneByOne(1)
,它将跳过索引0