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

100
Vistas
do-while loop still running even thought the conditional is false

const arr1 = [1, 2, 3, 4, 5];
const arr2 = [];
let index = Math.floor(Math.random() * arr1.length);

for(let i = 0; i < arr1.length; i++) {
    arr2.push(arr1[index]);
    do {
        index = Math.floor(Math.random() * arr1.length);
        console.log(arr2.includes(arr1[index])); //thís is to see the result
    } while (arr2.includes(arr1[index]))
}

console.log('arr2: ', arr2);

I want to make the new unordered array from the first array. But when I run this code, the loop becomes an infinite loop although the conditional is false. My question is the reason make the loop still running with the false conditional?

enter image description here

about 4 years ago · Juan Pablo Isaza
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