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

152
Visualizações
Conditional check in JavaScript not working

I am trying below code but it's not working as expected. I wanted to check if the cell Value has India or UnitedStatedofAmerica or Germany or Switzerland then go inside and if it's undefined, null or blank, or it doesn't contain the text location then go to else and set the value to ROW, But its not working.

So each time it give me results ROW even if cell have India or UnitedStatedofAmerica and when its null it goes inside the true condition and throw error for split as cell.Value is null

3 Example cell.Value

"Lorem Ipsum is simply dummy text of the printing and typesetting;Location India, Mumbai;Lorem Ipsum is simply dummy text of the printing and typesettingLorem Ipsum is simply dummy text of the printing and typesetting"

"Location India;Lorem Ipsum is simply dummy text of the printing and typesettingLorem Ipsum is simply dummy text of the printing and typesetting;Lorem Ipsum is simply dummy text of the printing and typesettingLorem Ipsum is simply dummy text of the printing and typesetting"

"Lorem Ipsum is simply dummy text of the printing and typesettingLorem Ipsum is simply dummy text of the printing and typesetting;Lorem Ipsum is simply dummy text of the printing and typesettingLorem Ipsum is;Location United Stated of America; simply dummy text of the printing and typesetting"

if (cell.Value.split('Location')[1].split(',')[0].replace(/\s/g, "") === "India" || cell.Value.split('Location')[1].split(',')[0].replace(/\s/g, "") === "Germany" || cell.Value.split('Location')[1].split(',')[0].replace(/\s/g, "") === "UnitedStatesofAmerica" || cell.Value.split('Location')[1].split(',')[0].replace(/\s/g, "") === "Switzerland" || cell.Value !== 'undefined' || cell.Value !== null || cell.Value !== "" || cell.Value.toLowerCase().indexOf("Location") !== -1) {
  persona.country = cell.Value.split('Location')[1].split(',')[0].replace(/\s/g, "");
} else {
  persona.country = "ROW"
}

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

0

You could simplify some parts with some variables and an array of wanted countries.

const
    value = cell.Value || '',
    country = value.split('Location')?.[1]?.split(',')[0].replace(/\s/g, ""),
    countries = ["India", "Germany", "UnitedStatesofAmerica", "Switzerland"];

persona.country = countries.includes(country)
    ? country
    : "ROW";
about 4 years ago · Juan Pablo Isaza Relatório

0

If cell.Value is null or undefined then calling .split will throw an error. You could just add a falsy check for cell.Value at the beginning of the toif statement.

if(cell.Value && cell.Value.split...
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