JavaScript Array flatMap() MethodThe 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
|