JavaScript flatMap and fill.

Edison Devadoss
2 min readNov 22, 2020

Hi friends, in this article I will explain JavaScript flatMap and fill method. These two methods are array methods.

https://www.photopea.com/

flatMap

The flatMap() method returns a new array formed by applying a given callback function to each element of the array and then flattening the result by one level. It is identical to a map() followed by a flat() of depth 1, but slightly more efficient than calling those two methods separately.

Example

https://carbon.now.sh/

The above example returns flat the 1 depth array and multiplies with 10.

fill

The fill() method changes all elements in an array to a static value, from a start index (default 0) to an end index (default array.length). It returns the modified array.

Example

https://carbon.now.sh/

In the above example fill with static value in the array element. 0 is the static value. 1 is the starting index 3 is the ending index. It returns [ 1, 0, 0, 4 ] .

--

--

Edison Devadoss

Software developer / JavaScript / React / React Native / Firebase / Node.js / C Programming / Book Reader