- Home
- /
- Tutorials
- /
- DSA Tutorial
- /
- Linear Search and When to Use It
Searching
Linear Search and When to Use It
Linear search is the one everybody dismisses. On the sizes most code actually deals with, it is frequently the fastest option and always the clearest.
The built-ins are all linear
Five ways to scan
javascript
const users = [{ id: 1, name: "Ada" }, { id: 2, name: "Grace" }]
users.find((u) => u.id === 2) // the element, or undefined
users.findIndex((u) => u.id === 2) // the index, or -1
users.some((u) => u.id === 2) // true or false
users.filter((u) => u.id > 1) // every match
;[1, 2, 3].includes(2) // primitives only