I have an array that holds five numbers. I want an if statement to check if the first three numbers in the array are the same. What is the simplest way to write the condition?
Can I do something like this…
let numberArray = [3, 3, 3, 4, 5]
if (numberArray[0] === numberArray[1] === numberArray[2]) {
console.log("the first three numbers of the array match");
}
Or should I approach it like this…
let numberArray = [3, 3, 3, 4, 5]
if (numberArray[0] === numberArray[1] && numberArray[1] === numberArray[2]) {
console.log("the first three numbers of the array match");
}