Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

linear search example js

function linearSearch(arr, item) {
  // Go through all the elements of arr to look for item.
  for (var i = 0; i < arr.length; i++) {
    if (arr[i] === item) { // Found it!
      return i;
    }
  }
  
  // Item not found in the array.
  return null;
}
Source by www.freecodecamp.org #
 
PREVIOUS NEXT
Tagged: #linear #search #js
ADD COMMENT
Topic
Name
7+3 =