Javascript Array FlatMap Example | JS Array flatMap()

Javascript Array FlatMap Example | JS Array flatMap()

Javascript Array flatMap() is an inbuilt method that maps each element using the map function, then flattens the result into the new array.

Javascript Array flatMap() is an inbuilt method that maps each element using the map function, then flattens the result into the new array. It is identical to the Javascript Array  map followed by the Javascript Array  flat of depth 1, but the flatMap() method is often quite useful, as merging both into one method is slightly more efficient.

Javascript Array FlatMap Example

The array.flatMap() is an inbuilt Javascript function which is used to flatten the input array element into the new array. Array flatMap() first of all map every element with the help of mapping function, then flattens the input array element into the new array.

The syntax for flatMap() function is following.

let new_array = arr.flatMap(function callback(currentValue[, index[, array]]) {
    // return element for new_array
}[, thisArg])

It returns a new array with each element being the result of the callback function and flattened to a depth of 1. It has a callback function as a parameter that has the following arguments.

javascript array flatmap js flatmap

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Javascript Array lastIndexOf Example | JS Array lastIndexOf()

Javascript Array lastIndexOf Tutorial | JS Array lastIndexOf() Example. A lastIndexOf() method searches an array for a specified item and returns its index.

Javascript Array lastIndexOf Example | JS Array lastIndexOf()

Javascript Array lastIndexOf Tutorial | JS Array lastIndexOf() Example. A lastIndexOf() method searches an array for a specified item and returns its index.

Javascript Array copyWithin Example | JS Array copyWithin

Javascript Array copyWithin() is an inbuilt method that copies part of an array to the same array and returns it, without modifying its size i.e, copies array element of an array within the same array.

Javascript Array copyWithin Example | JS Array copyWithin

Javascript Array copyWithin() is an inbuilt method that copies part of an array to the same array and returns it, without modifying its size i.e, copies array element of an array within the same array.

JavaScript Array Reverse Example | JS Array Reverse() Method

JavaScript Array Reverse Example | JS Array Reverse() Method. The reverse() method reverses the order of the items. It does not change the original array.