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

101
Vistas
What's the most succinct syntax to preserve only specific keys from a large JavaScript object?

In other words, I want to clean objects by dropping most of their keys.

Say a third party API returns JSON with a large number of of attributes you don't care about.

obj = {
  name: ...,
  id: ...,
  description: ...,
  blah: ...,
  bloop: ...,
  blip: ...,
  ... 12 others
}

But you're only interested in, say, id and name.

I know there's spread syntax object destructuring that allows me to put these into separate variables.

const { id, name } = obj

Is there a way to transform obj into a new object that looks like the following without explicitly accessing every key and value and making an object out of those?

newObj = {
  id: ...,
  name: ...
}

I'm curious if there's a one-liner I can put into map to transform a whole array of these objects.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Just destructure the wanted properties and use short hand properties for the object.

result = array.map(({ id, name }) => ({ id, name }));
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