Eduard Nistru Eduard Nistru - 5 months ago 13
Node.js Question

Return array value with forEach()

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 of
console.log(item.name)
but it doesn't work. Thanks a lot in advance! Newbie out.

Answer

try map instead of foreach

req.body.items.map(function(item){ return item.name; })
Comments