【问题标题】:How to foreach object in the array on nodejs如何在nodejs上的数组中foreach对象
【发布时间】:2022-11-13 23:53:26
【问题描述】:

`

const data = [{'name': 'Apip'}, {'name': 'Rohmat'}, {'name': 'ujang'}]
data.forEach(function (response) {
     res.json(response)
})

`

我做了上面的代码它不起作用,然后它抛出一个错误“发送到客户端后无法设置标题”

【问题讨论】:

  • 你能分享你正在寻找的输出吗?

标签: node.js mongodb


【解决方案1】:

您必须批量发送数据:

const data = [{'name': 'Apip'}, {'name': 'Rohmat'}, {'name': 'ujang'}]
res.json(response)

Why can't I use res.json() twice in one post request?

【讨论】:

    猜你喜欢
    • 2021-11-09
    • 1970-01-01
    • 1970-01-01
    • 2016-11-24
    • 2010-11-24
    • 2021-04-14
    • 2018-05-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多