Reputation: 93
I have a below data and i want to show only few fields _id, courseBy
in my response
const result = [{
_id: 6104106f3ff78f39b81bf143,
category: 't-shirts',
courseBy: ' shivangi joshi',
thumbnail: 'uploads\\shirt.jpg',
about: ' shirts',
},
{
_id: 610410763ff78f39b81bf147,
category: 'watches',
courseBy: ' shivangi joshi',
thumbnail: 'uploads\\shirt.jpg',
about: ' shirts',
}]
Response data:-
res.status(200).send({
statusCode: "200",
"_id":result[0]._id,
"courseBy": reslut[0]._courseBy
});
here i'm only getting single record but not the both the records please help me thanks in advance
Upvotes: 0
Views: 35
Reputation: 5437
res.status(200).send({
statusCode: "200",
data: result.map(({ _id, courseBy }) => ({ _id, courseBy }))
});
Upvotes: 2