i'm totally newbie in programming - actually i'm learning JavaScript and i have a problem with one task. There is a code below:
let myFewNumbers = [1, 4, 3, 2, 4, 5, 1, 2, 5, 9];
let myIndex = 0;
for (i = 0; i < myFewNumbers.length; i++) {
for (j = 0; j < myFewNumbers.length; j++) {
if (i != j && myFewNumbers[i] === myFewNumbers[j]) {
myIndex = j;
break;
}
}
}
console.log(myIndex);
I don't know how to stop atribution to variable because when "if" is true then changes variable "myIndex" to "j" but i want to know first number that repeats not last one. I know that rest of my code is ok and i don't want to change anything in this but i think there is something missing in "if"