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

308
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 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