- 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.