1. Function declaration
Receive an array and the value we want to find.
function linearSearch(arr, target)Typorithm · easy
Step 1 of 8 · intro card
Search Algorithms
Linear Search scans values one by one until it finds the target.
Linear Search is the simplest way to find a value in an array.
It checks each item from left to right and stops as soon as the target is found.
If the target never appears, the function returns -1.
Scan from index 0 to the end.
Compare each value with target.
Return the matching index.
Worst-case time is O(n).
function linearSearch(arr, target) {
for (let i = 0; i < arr.length; i++) {
if (arr[i] === target) {
return i;
}
}
return -1;
}Connect each part of the code to the concept before you type.
Receive an array and the value we want to find.
function linearSearch(arr, target)Check each index from left to right until the target is found.
for (let i = 0; i < arr.length; i++)Compare the current value with the target using strict equality.
arr[i] === targetReturn the index where the target was found.
return iReturn -1 after the loop if the target never appears.
return -1Read the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.
Algorithm lab · interactive
InputArray [1,3,5,7,9,11,13,15] · target 9
Follow temporary values, local state and supporting structures at this step.
Local state · indices and saved values
Around this step
Small, reproducible examples · ← → step · Space play/pause · Home/End first/last state