if I have an array myArray which I am looping through:
for(var i=0;i<myArray.length;i++) {
if(myArray[i] == myArray[i+1])
//do something
}
Clearly, myArray[i+1] will fail on the last iteration. Short of testing if i == (myArray.length - 1), is there a clean way to not fail on that if statement and just have it evaluate to false (if myArray[i+1] is out of bounds)?
myArray[i]withundefined. Regardless, best to stop earlier, as shown in KennyTM's answer.