JSFiddle - React, Tailwind, and code Playground
by Luis Perez
JavaScript
// No need to double evaluate the conditon, start with an assertion, and then aim to Disprove it
var theSame = true;
var myArray = [1, 1, 3, 1];
// You need to iterate over the array, not sure why you had the while at the line prior.
for (let i in myArray){
if (myArray[i] != myArray[0]) {
theSame = false;
// You could break here, if that's the only thing you want to check for.
}
}
// You'd stated you wanted to alert only if the array was in total not the same element.
if (!theSame)
alert("Not Equal");
// The whole above set can be placed in a function, where the array is the argument for it to make the code modular.