【问题标题】:How to print out multiple responses not just the first line如何打印出多个响应而不仅仅是第一行
【发布时间】:2022-10-06 04:10:12
【问题描述】:
  if(response){
            const temp = response[0];
            const recipient_id = temp[\"recipient_id\"];
            const recipient_msg = temp[\"text\"];      

我有这个 if 语句,它只打印出第一个响应(响应 [0]),我将如何打印出多个响应,而不管数量是多少,而不仅仅是第一行。

  • 如果没有更多上下文,这是不可能回答的。你说“打印”,但这里没有任何东西可以被认为是打印。你需要一个循环

标签: javascript reactjs


【解决方案1】:

您可以使用Array#forEach 或for ... of 循环来遍历数组。

for (const r of response) {
    console.log(r); // or extract individual properties to log
}

【讨论】:

    猜你喜欢
    • 2016-11-04
    • 2021-11-20
    • 1970-01-01
    • 2019-06-06
    • 2020-04-28
    • 1970-01-01
    • 2012-03-26
    • 2021-12-22
    • 2011-02-18
    相关资源
    最近更新 更多