forEach(): The forEach() function is used to iterates through all the entries of the array.
Example: To find the sum of all the numbers in an array of numbers.
map(): The map() method is used to iterate through all the entries of the array, modifies them and returns a new array but the old array is not manipulated.
Example: To multiply each number of the array by 2 and generate a new array.
2, 4, 6, 8, 10
Example: The map() method can also be used to extract attributes from an array of objects and store it in another array.
2, 4, 6
filter(): The filter() method is used to iterate through all the entries of the array and filters out required entities into another array.
Example: To filter all objects where flag is 1.
flag:1, a:1 flag:1, a:3
find(): The find() method is used to iterate through all the entries of the array and returns the record matching with a particular condition.
Example: To find a object where flag is 0.
Note: The filter() method returns an array of objects and find() method returns a single object.
- Inline HTML Helper - HTML Helpers in ASP.NET MVC
- ES6 | New String Methods
- Ruby Hook Methods
- ReactJS | Methods as Props
- HTTP GET and POST Methods in PHP
- File Allocation Methods
- jQuery | Selectors and Event Methods
- Accessing Attributes and Methods in Python
- jQuery UI | draggable() and droppable() methods
- Abstract Methods in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.