Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

154
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

0

Shortest way I can think of:

const updatedRecords = records.map(({_id, customername})=> ({_id, customername}));
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda