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

314
Vistas
How do I check if condition is true and run code? It's not working code below

I tried to check if iteam1 is in the array iteamList and then run the code.

var itemsLists =  ["item1", "item2", "item3", "item4","item5"]; 
if (itemsLists === "item1") {
console.log("Here is iteam 1");} 
else{
console.log("it's not iteam 1");};

//output it's not iteam 1

I was expecting Here is iteam 1

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

A scalar value will never be equal to an array - as you said you need to check if it is IN the array. The simplest way is to use array.includes() but arrays also have find and filter methods to search for matches....

if (itemsLists.includes('item1')) {
about 4 years ago · Juan Pablo Isaza Denunciar

0

Use this to check if this string exists in the list:

var itemsLists =  ["item1", "item2", "item3", "item4","item5"]; 
if (itemsLists.includes("item1") == true) {
    console.log("item in list");
}
else {
    console.log("item not in list");
}

Output:

"item in list"

This should help you with your problem. Also, please try to research and resolve your problem before posting to stack overflow.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Use the includes function to check if this string exists in the list:

For example:

if (itemsLists.includes("item1")) {
    console.log("Here is item 1");
} else {
    console.log("it's not item 1");
}
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