Which fix removes the bug?
if (names.indexOf(target)) {
console.log('found');
}
- Compare the result to
-1 - Swap the arguments around
- Use
indexOfon a copy - Sort
namesbefore the check
indexOf returns 0 for the first element, which is falsy — test
Play Problem Solving ▸
!== -1.