Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

151
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda