Search. Linear Search.
Difficulty: easy
The Task#
Find the position of a specific element in a list (or array).
The list is not sorted, it may contain strings, numbers or objects. The distribution of the element in a list is unknown, we can't say if it sorted or not.
The Algorithm#
A linear search algorithm is a method for finding an element within a list. It sequentially checks each element of the list until a match is found or the whole list has been searched.

Application#
If we need to find one value in an unsorted array, the linear search algorithm is a good option. If many values need to be found in the same array, then pre-processing the array -- like using a sorting algorithm first -- and using another search algorithm, like a binary search algorithm is a better approach.
Usage Example#
Let's say we want to implement a linear search for the phone book array that contains a list of users (objects with name and phone).
To make our linear search a little bit more useful we will make it work not only with numbers and strings but also with objects. This option will allow us to be more flexible when searching the array.
const janeNamesake = { name: 'Jane', phone: '+111111111114' };
This lesson preview is part of the JavaScript Algorithms course and can be unlocked immediately with a \newline Pro subscription or a single-time purchase. Already have access to this course? Log in here.
Get unlimited access to JavaScript Algorithms, plus 0+ \newline books, guides and courses with the \newline Pro subscription.
