Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

152
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

0

Shortest way I can think of:

const updatedRecords = records.map(({_id, customername})=> ({_id, customername}));
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda