Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
60
rated 0 times [  63] [ 3]  / answers: 1 / hits: 23034  / 8 Years ago, sun, july 3, 2016, 12:00:00

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.


More From » arrays

 Answers
18

try map instead of foreach



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

[#61531] Thursday, June 30, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
raymondd

Total Points: 620
Total Questions: 112
Total Answers: 94

Location: Namibia
Member since Mon, Feb 21, 2022
2 Years ago
;