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

281
Visualizações
I'm struggling with the proper vernacular for searching, but how can I remove all keys with empty/null/undefined values from a flat object?
  {
        "Gender": "male",
        "SiteId": -99,
        "LastName": "Bobby",
        "BirthDate": "2000-01-15T06:00:00.000Z",
        "FirstName": "Ricky",
        "HomeLocation": {},
        "ClientCreditCard": {},
        "CustomClientFields": {}
    }

I've tried a few options I found here, but can't seem to understand what I'm doing wrong. I've tried:

let o = Object.keys(obj)
  .filter((k) => obj[k] != null)
  .reduce((a, k) => ({ ...a, [k]: obj[k] }), {});

and

var output = JSON.parse(JSON.stringify(obj));

Also, any recommended courses that focus on data manipulation for arrays/objects would be appreciated!

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

The function you are looking for is Object.entries()

This will give you an array that looks like this: [[key, value], [key, value], [key, value]]

From there you can use that filter function to check if the value matches your condition.

Object.entries(yourObject).filter(item => item[1] != null)

Note: I don't think that checking only for != null will be enough based on the sample you gave.

about 4 years ago · Santiago Gelvez 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