JavaScript Array flatMap() Method17 Mar 2025 | 2 min read The flatMap() method is a combination of flat() and map() methods. This method initially maps each array element through a mapping function, then flatten up the array with depth value as 1. SyntaxParameterscallback- It is a function which produces an element for the newly created array and carries the following three arguments:
ReturnIt returns a new array where each element is the result of the callback function. JavaScript Array flatMap() Method ExamplesLet's see the below examples to understand better: Example1 It is a simple example to know the use of flatMap() method. Test it NowOutput: ![]() Example2 Using flatMap() method with two different array elements. Test it NowOutput: ![]() Example3 This example shows the name of the fruit which each member likes. Test it NowOutput: ![]() Example4 An example to split the sentences into individual words. Test it NowOutput: ![]() It is clear in the output that each sentence is seperated from one another and forming individual word. Next TopicJavaScript Array |
JavaScript Array method The JavaScript array method is used to arrange the array elements in some order. By default, method follows the ascending order. Syntax The method is represented by the following syntax: array.sort(compareFunction) Parameter compareFunction - It is optional. It represents a function that provides an...
1 min read
JavaScript Array reduce() Method The reduce() method reduces the given array into a single value by executing a reducer function. The user implements the reducer function that works on every element present in the array. Reducer Function The reducer function is the user implemented code. It uses the...
2 min read
JavaScript Array method The JavaScript array method removes the last element from the given array and return that element. This method changes the length of the original array. Syntax The method is represented by the following syntax: array. Return The last element of given array. JavaScript Array method...
1 min read
JavaScript Array method The JavaScript array method fills the elements of the given array with the specified static values. This method modifies the original array. It returns undefined, if no element satisfies the condition. Syntax The method is represented by the following syntax: arr.fill(value[, start[, end]]) Parameter value...
1 min read
JavaScript Array method The JavaScript array method is used to invoke the specified function once for each array element. Syntax The method is represented by the following syntax: array.forEach(callback(currentvalue,index,arr),thisArg) Parameter callback - It represents the function that test the condition. currentvalue - The current element of array. index - It...
1 min read
JavaScript Array Method The method creates a new array iterator object that carries the values specified at each array index. We can iterate the array elements via loops or iterator methods. Syntax array.; Parameter It does not hold any parameter as such. Return It creates and returns a newly created...
2 min read
JavaScript Array Method The JavaScript array method combines two or more arrays and returns a new string. This method doesn't make any change in the original array. Syntax The method is represented by the following syntax: array.concat(arr1,arr2,....,arrn) Parameter arr1,arr2,....,arrn - It represent the arrays to be combined. Return A new...
1 min read
JavaScript Array method The JavaScript array method is used to search the position of a particular element in a given array. It behaves similar to indexOf() method with a difference that it start searching an element from the last position of an array. The ...
1 min read
JavaScript Array Method The method creates and returns a new array from different a number of arguments. It does not focus on the type and number of arguments. Similar to Array, it also provides a constructor that handles the integer arguments, but in a...
2 min read
JavaScript Array method The JavaScript array method changes the sequence of elements of the given array and returns the reverse sequence. In other words, the arrays last element becomes first and the first element becomes the last. This method also made the changes in...
1 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India