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

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

0

Clone the object and delete the property:

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

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

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 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