首页 > 解决方案 > 在node.js中通过post方法发送数组数据,如何在控制台上打印我试过这个

问题描述

详细信息:如何仅在通过 post 方法在服务器上发送的数组的控制台上打印特定值

router.post('/', function(req, res, next) {
    var mj = new Array();
    mj = req.body.equip;
    console.log("this" + req.body.equip[]);
    console.log(mj);
});

我用了这个,但它没有给出结果

 <input type="text" name="equip[]">
 <input type="text" name="equip[]">
 <input type="text" name="equip[]">

标签: javascriptnode.js

解决方案


我认为下面的代码将帮助您打印每个值。

var array=req.body.equip;
array.forEach(function(element) {
    console.log(element);
}, this);

推荐阅读