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

139
Visualizações
Remove objects from each object in an array of objects

I want to improve the table performance with a large dataset by removing all nested objects which the table doesn't use. I don't want to name the keys because they will vary from dataset to dataset. This needs to be a reusable helper function that removes objects based on typeof rather than a key.

Example data:

const data = [
  { test: 1, notes: [] },
  { test: 2, notes: [] },
  { test: 3, notes: [] }
];

expected result

[
  { test: 1 },
  { test: 2 },
  { test: 3 }
];

What I've tried:

  const simpleRows = (arr) => {
    var rows = arr.map(({ notes, ...keepAttrs }) => keepAttrs);
    return rows;
  };

  const rows = simpleRows(data) // This works but I have hardcoded the key 'notes' which I don't want

What is the most efficient way to remove all objects from each object in an array of objects in a large dataset (~10000 objects in the array) without hardcoding the key, and without an external library?

Thanks

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can filter the entries of each object and create a new object from the filtered entries:

const data = [
  { test: 1, notes: [] },
  { test: 2, notes: [] },
  { test: 3, notes: [] }
]
const result = data.map(obj => Object.fromEntries(Object.entries(obj).filter(([_, v]) => !Array.isArray(v))))
console.log(result)

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