Higher-Order Functions

Find() vs. Filter() in JavaScript

Jinath yasmin
May 27, 2021

what is Higher-Order Functions?

Functions that operate on other functions, either by taking them as arguments or by returning them, are called higher-order functions.

When we handle an array in JavaScript, we may need to find a single item in the array collection, which is quite easy to find using appropriate methods.

FILTER()

The filter() method, rather than deleting elements from the existing array, builds up a new array with the only elements that pass the test. It does not modify the existing array.

input
The syntax of a filter() Method
output

FIND()

The find() method returns the first value that pass the test from the array. Once it pass the test, it will not check the remaining values in the array.

The syntax of a find() Method
Output

CONCLUSION

find() method is a better option since it is faster than filter() & filter() itself relies on find() method.

--

--

No responses yet