用forEach()返回数组的值 [英] Return array value with forEach()
本文介绍了用forEach()返回数组的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
exports.send = function(req)要求返回存储在另一个对象中的数组的名称值。 ,res){
$
req.body.items.forEach(function(item){console.log(item.name)})
}
$ b
产品3
产品2
但是我不知道如何获得我想发送的HTML内容的值一个电子邮件地址我尝试使用
return item.name
而不是console.log(item.name)
但它不起作用。提前感谢!新手出来。解决方案试试map而不是foreach
req.body.items.map(function(item){return item.name;})
I am looking to return the name value of an array stored in another Object.
exports.send = function(req,res){ req.body.items.forEach(function(item){console.log(item.name)}) }
Console:
Product 3 Product 2
But I don't know how to obtain those values for an HTML content which I want to send it to an email address. I tried with
return item.name
instead ofconsole.log(item.name)
but it doesn't work. Thanks a lot in advance! Newbie out.解决方案try map instead of foreach
req.body.items.map(function(item){ return item.name; })
这篇关于用forEach()返回数组的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文