The prompt is to find the index number of fourth occurrence of the number in an array. I am trying to implement break in the for loop statement, I am not sure how to make it work. Here is my code:
let array = [0,4,4,3,2,1,4,5,6,4,6,9];
for (i = 0; i <= array.length; i++){
if (array[i] === 4){
console.log("The fourth occurrence of 4 is:", i)
break;
}
}
Suppose output
The fourth occurrence of 4 is: 9