What is Linear Search?
Check every item from left to right until the target is found.
Type a tool name, format or task
Check every item from left to right until the target is found. Interactive step-by-step animation with JavaScript code, complexity and front-end use cases.
Loading animation...
Check every item from left to right until the target is found. Start at the first item. Compare it with the target. Stop when it matches, or when the list ends. Time complexity: O(n). Space complexity: O(1). Array.includes, indexOf and find all work like this. Perfect for small or unsorted lists.
Check every item from left to right until the target is found.
Time: O(n). Space: O(1).
Array.includes, indexOf and find all work like this. Perfect for small or unsorted lists.
No. This converter runs in your browser for ordinary use, so the input is not sent to a backend by this tool.
Keep working without searching again.
Look for 42 by checking every item from left to right.
function linearSearch(arr, target) {for (let i = 0; i < arr.length; i++) {if (arr[i] === target) return i;}return -1;}
Tip: use the arrow keys to step and the space bar to play or pause.