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

270
Visualizações
How to return blank and not 0, while mapping through a 2D array using GAS?

Right now, the code does divides each element by 100, so I can get it in the correct % format. However, when the element iterated is blank, it gives me 0 while this would have to be blank and I can't seem to make it right:

The data in a 2D array:

[
 ["MARLEY SC35-45 PIPE CLIP PVCu","82",1,0,11.96,-68],
 ["MARLEY SC35-45 PIPE CLIP PVCu","110",1,0,10.02,],
 ["MARLEY SC35-45 PIPE CLIP PVCu","160",1,0,32.62,-68]
]

The code I'm running returns 0, but this would have to be blank.

let dataLab3 = dataLab.map(function (v) { return [v[5]/100] })

Current result:

-68
-0
-68

..while it should be:

-68

-68

I'm not sure where I'd apply a filter in this case.

Appreciate your help.

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

0

If v[5] does not exist, then return "" (or null):

let dataLab3 = dataLab.map(v => v[5] ? [v[5]/100] : "" )
about 4 years ago · Juan Pablo Isaza Relatório

0

So add a check in the map to see if it has a value either with a truthy check

return v[5] ? [v[5]/100] : '';

or check if it is undefined if the value can be zero.

const dataLab = [
  ["MARLEY SC35-45 PIPE CLIP PVCu","82",1,0,11.96,-68],
  ["MARLEY SC35-45 PIPE CLIP PVCu","110",1,0,10.02,],
  ["MARLEY SC35-45 PIPE CLIP PVCu","160",1,0,32.62,-68]
];

const dataLab3 = dataLab.map(function (v) {
  return v[5] !== undefined ? [v[5]/100] : undefined;
});

console.log(dataLab3);

return whatever you want in the second part of the ternary operator.

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