JavaScript Higher Order Functions Cheatsheet

Sarath Adhithya
2 min readOct 24, 2022

--

  1. map: Calls a defined callback function on each element of an array, and returns an array that contains the results.
  2. forEach: Performs the specified action for each element in an array.
  3. filter: Returns the elements of an array that meet the condition specified in a callback function.
  4. find: Returns the value of the first element in the array where the predicate is true, and undefined otherwise.
  5. some: Determines whether the specified callback function returns true for any element of an array.
  6. reduce: Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result and is provided as an argument in the next call to the callback function.
  7. every: Determines whether all the members of an array satisfy the specified test.
  8. findIndex: Returns the index of the first element in the array where the predicate is true, and -1 otherwise.
  9. sort: Sorts an array in place. This method mutates the array and returns a reference to the same array.
JavaScript Higher Order Functions Cheatsheet
JavaScript Higher Order Functions Cheatsheet

Difference between map and forEach:

forEach: This iterates over a list and applies some operation with side effects to each list member and does not return anything. Similar to for loop

map: This iterates over a list, transforms each member of that list and returns another list of the same size with the transformed members. It does not mutate the array on which it is called.

--

--

Sarath Adhithya

Full Stack Developer | Blockchain Enthusiast | Frontend ❤️ | MERN | NEXTJS | REACTJS