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

204
Visualizações
How to replace all nulls with dash in object?

I have an object and for all keys that have a null value I want to replace this null with an empty string (or a dash in my case)?

For example

Obj = {

key1: null,
key2: null,
key3: true,
...
key_n: null

}

Turns into

Obj = {

key1: "-",
key2: "-",
key3: true,
...
key_n: "-"

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

0

This will work.

const Obj = {
  key1: null,
  key2: null,
  key3: true,

  key_n: null
};

for (const key in Obj) {
  const val = Obj[key];

  if (val === null) {
    Obj[key] = "-";
  }
}
console.log(Obj);

about 4 years ago · Juan Pablo Isaza Relatório

0

const obj = {
  key1: null,
  key2: null,
  key3: true,
  key_n: null
};
Object
  .entries(obj)
  .forEach(function ([key, value]) {
    if (value === null) {

      this[key] = '-';
    }
  }, obj); // make use of `forEach`'s `thisArg` parameter.

console.log({ obj });

about 4 years ago · Juan Pablo Isaza Relatório

0

You just have to match whether a key's corresponding value is null or not , if yes then change it to underscore.

Obj = {

    key1: null,
    key2: null,
    key3: true,
    key_n: null

    }

    Object.keys(Obj).map(key=>{
        if(!Obj[key])Obj[key] = "_"
    })
    console.log(Obj)

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