Search for an item and exit when found:
let names = ["Alice", "Bob", "Charlie"]
let target = "Bob"
let found = false
for (let name of names) {
if (name === target) {
found = true
break
}
}
console.log(found ? "Found" : "Not found")
The break is optional but efficient. Without it, the loop checks every item even after finding a match.