0

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

2
  • So why are you just returning one thing if you want many? Sounds like you want array map and convert the one array into a different array. Commented Jul 30, 2021 at 17:22
  • 1
    i'm only getting single record but not the both the records” Can you point to a spot in your code which you believe should print both records? Commented Jul 30, 2021 at 17:22

1 Answer 1

2
res.status(200).send({
    statusCode: "200",
    data: result.map(({ _id, courseBy }) => ({ _id, courseBy }))
 });
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.