DEV Community

Cover image for Map, Filter, Find
Kaniz Mokammel Mim
Kaniz Mokammel Mim

Posted on

Map, Filter, Find

Map, Filter, Find

We all use arrays when working with JavaScript. An array is a data structure where the same element can be stored.We use Map, Filter, and Find to get elements from the array. Today I will try to explain Map, Filter, Find in a simple way.

Map:
The function of a map is to take the property from one array and return it to another array.Many may say that "foreach" can also be used to return the property from the array. Yes, that's right, but "foreach" can't automatically return a new array like "map", you have to push the property in an array
Using foreach:

Image description

Using Map:

Image description

So in the above pictures we can see that using "foreach" we have to push the property in a new array but "map" has made this task easier.

Filter :
Filter returns the properties of an array to a new array like "Map", but in this case we can access the property using the terms. For which only the necessary features can be found in an easy way without accessing an entire array.
In the image below, I did not take all the properties from the same array and only filtered the largest property from 10.

Image description

Find:
Find is usually called array method."Find" is used to get a value from an array and it does not return a value to any array. And in case of value return returns the first value like condition.
I am clearing the matter with an example, suppose
Number = [10,12,3,4,6,90], from this array I want to see properties greater than 10, here 12 and 90 have these 2 values as the largest property of 10, but "Find" is only the first Value 12 will be given as a result.

Image description

Top comments (0)