- Filter method ( filter())
- Map method ( map())
- Reduce method ( reduce())
- Find method ( find())
- Sort method ( sort())
We will learn how to chain all the array methods together.
We want to do two things.
- Filter those elements whose price is greater than 100 using filter() method.
- Map those elements to a new array with a new sale price(50% off).
A quicker way to achieve this is by using array method chaining. All the array methods work on arrays and return arrays. So we can easily chain these methods.
- The output in both the cases remains same. The second method is called chaining of array methods which makes the code a little more concise.
- Since the filter method returns an array we can chain it to the map method which works on an array and vice-versa.
- This process can be applied to all the array methods which makes the code concise.
- This method is not only applicable for arrays, but we can use them on strings also, as long as the methods return and work on strings. The same principle will be applied.
- jQuery | chaining()
- Node.js | Promise Chaining
- What is Chaining in Node.js ?
- Array Helper Methods in ES6
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.