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?