Javascript Array flat() is an inbuilt method that creates a new array with all sub-array elements concatenated into it recursively up to the specified depth. It returns a new array with the sub-array elements concatenated into it.

Javascript Array Flat Example

As its name suggests, the Array flat() method available on an Array prototype returns the new array that’s the flattened version of an array it was called on. If we do not provide arguments passed-in, then the depth of 1 is assumed.

The syntax of the Javascript Array flat() method is the following.

let newArray = arr.flat([depth]);

The depth level is specifying how deep a nested array structure should be flattened. Defaults to 1. It is an optional parameter.

#javascript #flat #array.prototype.flat #js

Javascript Array Flat Example | Array.prototype.flat()
1.40 GEEK