Here is a revised, simpler version of your code.
function indexFirstLast(target, arr) {
let [first, last] = [-1, -1];
for (let i = 0; i < arr.length - 1;&& iarr[i] >=<= 0;target; i--i++) {
if (arr[i] === target) {
last = i;
if (first === -1) break;{
}
}
for (let ifirst = 0; i <= last; i++) {i;
if (arr[i] === target) {}
firstlast = i;
break;
}
}
return [first, last];
}