Chaining of Array Methods in JavaScript Last Updated : 09 Jul, 2020 Comments Improve Suggest changes Like Article Like Report There are some methods in JavaScript that can loop through the array. We already have a knowledge about these array methods. 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. Example: Java const products = [ // Here we create an object and each // object has a name and a price { name: 'dress', price: 600 }, { name: 'cream', price: 60 }, { name: 'book', price: 200 }, { name: 'bottle', price: 50 }, { name: 'bedsheet', price: 350 } ]; 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). Example: Java <script> const products = [ // Here we create an object and each // object has a name and a price { name: 'dress', price: 600 }, { name: 'cream', price: 60 }, { name: 'book', price: 200 }, { name: 'bottle', price: 50 }, { name: 'bedsheet', price: 350 } ]; // Filters the elements with // price above 100 const filtered = products.filter( product => product.price > 100); const sale = filtered.map(product => { return `the ${product.name} is ${product.price / 2} rupees`; }); // log the sale price to console console.log(sale); </script> Output: 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. Example: javascript <script> const products = [ { name: 'dress', price: 600 }, { name: 'cream', price: 60 }, { name: 'book', price: 200 }, { name: 'bottle', price: 50 }, { name: 'bedsheet', price: 350 } ]; // Writing the different array methods // on different lines increases the // readability const sale = products .filter(product => product.price > 100) .map(product => `the ${product.name} is ${product.price / 2} rupees`); document.write(sale); </script> Output: Conclusion: 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. Comment More infoAdvertise with us Next Article Chaining of Array Methods in JavaScript madhumanti_gupta Follow Improve Article Tags : JavaScript Web Technologies javascript-basics JavaScript-Misc Similar Reads JavaScript Array of() Method The Javascript array.of() method is an inbuilt method in JavaScript that creates a new array instance with variables present as the argument of the method.Syntax:Array.of(element0, element1, ....)Parameters: Parameters present are element0, element1, .... which are basically an element for which the 2 min read Important Array Methods of JavaScript JavaScript arrays are powerful tools for managing collections of data. They come with a wide range of built-in methods that allow developers to manipulate, transform, and interact with array elements.Some of the most important array methods in JavaScript areTable of Content1. JavaScript push() Metho 7 min read JavaScript Array Iteration Methods JavaScript Array iteration methods perform some operation on each element of an array. Array iteration means accessing each element of an array. There are some examples of Array iteration methods are given below: Using Array forEach() MethodUsing Array some() MethodUsing Array map() MethodMethod 1: 3 min read JavaScript Array Methods To help you perform common tasks efficiently, JavaScript provides a wide variety of array methods. These methods allow you to add, remove, find, and transform array elements with ease.Learn More on JavaScript ArrayTable of Content1. JavaScript Array length 2. JavaScript Array toString() Method3. Jav 8 min read JavaScript Array some() Method The some() method checks if any array elements pass a test provided as a callback function, returning true if any do and false if none do. It does not execute the function for empty elements or alter the original array.Syntaxarr.some(callback(element,index,array),thisArg);Parameterscallback: This pa 3 min read JavaScript Array concat() Method The concat() method concatenates (joins) two or more arrays. It returns a new array, containing the joined arrays. This method is useful for combining arrays without modifying the originals.Syntax:let newArray1 = oldArray.concat()let newArray2 = oldArray.concat(value0)let newArray3 = oldArray.concat 3 min read JavaScript Array forEach() Method The JavaScript Array forEach() method is a built-in function that executes a provided function once for each array element. It does not return a new array and does not modify the original array. It's commonly used for iteration and performing actions on each array element.Syntaxarray.forEach(callbac 3 min read JavaScript Array entries() Method The entries() method in JavaScript is used to create an iterator that returns key/value pairs for each index in the array.It allows iterating over arrays and accessing both the index and value of each element sequentially.Syntax:array.entries()Parameters:This method does not accept any parameters.Re 3 min read Array of functions in JavaScript Given an array containing functions and the task is to access its element in different ways using JavaScript. Approach: Declare an array of functions.The array of functions works with indexes like an array function. Example 1: In this example, the function call is initiated from the element of the a 2 min read JavaScript Array push() Method The push() method in JavaScript adds one or more elements to the end of an array and returns the new length of the array. It modifies the original array, increasing its length by the number of elements added.Syntaxarr.push(element0, element1, ⦠, elementN);ParametersThis method contains as many numb 3 min read Like