Higher order arrow function

I cannot understand what is the main difference between map. () and filter.() function. please, someone, explain to me.

filter removes items from an array. map mutates the items of an array. If you wanted to change all the letters in the alphabet to capitals, you would use map. If you wanted to take out all the vowels, you would use filter.

1 Like

The map() method creates a new array with the results of calling a provided function on every element in the calling array.

The filter() method creates a new array with all elements that pass the test implemented by the provided function.

@ArielLeslie’s explanation is good, just wanted to point out that both actually create a new array - neither modifies the original array.

2 Likes

@sipofwater and @ArielLeslie thank u very much guys for sharing your ideas and reply on my post.