Помогите: В поисках элемента

Рабочий код, проходит проверку. Пришлось завести еще одну переменную.
let numbers = [2, 4, 7, 4, 7, 2];
let number = 4;
let lastIndex = 0;
let num = 0;

for (let i = 0; i <= numbers.length-1; i++){
if (number === numbers[i]){
lastIndex = i;
num = numbers[i];
console.log(lastIndex)
} else if ( num !== number) {
lastIndex = -1;
}
}

let numbers = [2, 4, 7, 4, 7, 2];
let number = 4;
let lastIndex;
for (let i=numbers.length-1;i>=0;i–) {
if (numbers[i]==number) {
lastIndex=i;
break
} else {
lastIndex=-1;
}
}
console.log(lastIndex);

let numbers = [2, 4, 7, 4, 7, 2];
let number = 4;

let lastIndex = numbers.lastIndexOf(number);

let numbers = [2, 4, 7, 4, 7, 2];
let number = 4;
let lastIndex = -1;

for (let i = 0; i <= numbers.length - 1; i++) {
  if (numbers[i] == number) {
    lastIndex = i;
    } 
  }
console.log(lastIndex);