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
Is there a way to generate an object from another object by taking all its properties with except of one?

Having the initial object of this shape:

const initial = { a: 'a', b: 'b', c: 'c', d: 'd', ..., z: 'z' };

The result should contain all properties but without 'b' for example. I know there is a method like

const result = (({ a, b, c, d, ..., z }) => ({ a, c, d, ..., z }))(initial)

but in the case of an object with too many properties it's too much code.

Is there a shorter way to do that?

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

0

Clone the object and delete the property:

const result = {...initial};
delete result.b;
about 4 years ago · Juan Pablo Isaza Denunciar

0

Use Object.entries() to convert the object to an array. Use filter() to skip that element of the array. Use Object.fromEntries() to convert that result back to an object.

const result = Object.fromEntries(Object.entries(initial).filter(([key, value]) => key != 'b'))

You can also use destructuring. List all the properties you want to remove explicitly in the destructuring target, then combine the rest into a new object with ....

const initial = { a: 'a', b: 'b', c: 'c', d: 'd', z: 'z' };
const {b, ...result} = initial;
console.log(result);

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can copy the object, then delete a key:

const initial = { a: 'a', b: 'b', c: 'c', d: 'd', ..., z: 'z' };
const result = {...initial}; // copy the array
delete result.b;
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