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

120
Vistas
Verify data in `for` loop

I have an array with strings and I have a string - snowy for example. The task is to verify if the snowy is in arr, if yes, push it into one array, if no, push it into another. I am not sure that use of if(true) is correct way.

const arr = ["sunny", "rainy", "cloudy", "foggy"];

if (true) {
  for (let i = 0; i < arr.length; i++) {
    if (arr[i] === "snowy") {
      someArr.push("snowy");
      // some other conditions
    }
  }
  anotherArr.push("snowy");
  // some other conditions
}
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You can do something like

    const arr = ["sunny", "rainy", "cloudy", "foggy" ]

    if(arr.includes("snowy")){
        someArr.push("snowy");
    }else{
        anotherArr.push("snowy");
    }

In this case you are not going to need the for loop because the inludes() function looks for the string in the complete array. Here you have some tutorial of how to use the includes() function. https://www.w3schools.com/jsref/jsref_includes_array.asp

about 4 years ago · Juan Pablo Isaza Denunciar

0

Try with some

const arr = ["sunny", "rainy", "cloudy", "foggy"];

const someArray = [];
const anotherArray = [];

if (arr.some((item) => item === "snowy")) {
  someArray.push("snowy");
} else {
  anotherArray.push("snowy");
}

console.log({ someArray, anotherArray });

about 4 years ago · Juan Pablo Isaza Denunciar

0

const arr = ["sunny", "rainy", "cloudy", "foggy"];
const set = new Set(arr);
const someArr = []
const anotherArr = []
  
 set.has(data = "sunny") ? someArr.push(data) : anotherArr.push(data)
 
 console.log(someArr)
 
 console.log(anotherArr)
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