Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
filter array to limited key in reactjs

I have React.js app and I have the following result returned from mongodb. I am looking to filter the result to only contain _id and customername array key.

Example: {"Records": [{"_id": "6190d42febf87a4b4da5fcb0", "customername": "Henry"}, {"_id": "6190b608b17338658902ae0b", "customername": "Henry"}}

{
    "Records": [
        {
            "_id": "6190d42febf87a4b4da5fcb0",
            "customername": "Henry",
            "grade": "D",
            "entrydate": "14/11/2021, 05:17:30 pm",
            "reject": "10",
            "clone": "D24",
            "remark": "",
            "selectedprocess": "raw-material",
            "selectedcategory": "nitrogen",
            "weight": [10,30],
            "totalweight": 40
        },
        {
            "_id": "6190b608b17338658902ae0b",
            "customername": "Henry",
            "grade": "A",
            "entrydate": "14/11/2021, 03:08:53 pm",
            "reject": "5",
            "clone": "D24",
            "remark": "Mr GunGUn",
            "selectedprocess": "raw-material",
            "selectedcategory": "nitrogen",
            "weight": [5,30],
            "totalweight": 35
        }
    ]
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can use the Array.map to achieve the required result.

var updatedRecords = records.map((record)=> ({"_id": record._id,customername: record.customername })) 

The updatedRecords would consists of a new array that would only contain the id and the customername.

The preferred way would be that the backend handles this

about 4 years ago · Juan Pablo Isaza Report

0

Shortest way I can think of:

const updatedRecords = records.map(({_id, customername})=> ({_id, customername}));
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!