The Map() function takes an array and creates a new array by applying the function to each and every array’s element. Say if you have an array of decimal numbers and you want an array of rounded-off numbers, then there are multiple ways to do it .
You can achieve this by using for ( or foreach , for..in) loop and apply function to each element of an array as shown below :
Let’ see the implementation of the Map() function in the above example .
In simple terms, filter() is used to filter out some elements based on some conditions from an array and stored in an array. If the given condition is true then it will push the element in the new array otherwise it will not push the element.
This can be implemented by using for ( or foreach , for..in) loop as shown below.
Let’s see the above example with implementation of filter() :
And That’s all.
Thank you for reading.