Find() VS Filter() in JavaScript

CodeyMaze
Mar 5, 2022

--

Find() method returns the first element from the array that satisfies the provided testing function. Otherwise undefined is returned.

Let’s take an example of find() to find users with age less than 30 from a collection of users.

In the above example, we have used find() method on users array and check the condition of age on user object. It returns us the first element that matched the given condition.

Filter() method creates a new array with all elements that has passed the provided test condition.

Let’s take the same example to filters users with age less than 30.

In the above example, filter returns us elements which matches the given condition.

Subscribe to our Youtube channel for more videos:

https://www.youtube.com/channel/UCEXWe9R6-ppk4zhNo2JbtmQ

--

--

CodeyMaze
CodeyMaze

Written by CodeyMaze

Crafting Solutions Through Code & Words https://codeymaze.com Feel free to follow me :)

No responses yet