Linear search is the search everyone already knows: start at the first value and check each one in turn until you find the target or run out of values. It needs nothing from the data — no order, no index — so it works on arrays, linked lists, files and streams alike.
Each value is compared with the target until one matches or the array ends.
function linearSearch(nums, target) { for (let i = 0; i < nums.length; i++) { if (nums[i] === target) return i; // found: stop right away } return -1; // checked everything: not there}If the target is first, one check: O(1). If it's last or missing, n checks: O(n). On average, for a target that's present, about n/2 checks — still O(n). It uses O(1) extra space.
The same loop shape answers many questions: the last match (scan from the end), every match (collect instead of returning), the count of matches, or the minimum and maximum. They're all one pass, O(n).