What Is Flatten Array

Flattening an array is a process of reducing the dimensionality of an array. In other words, it a process of reducing the number of dimensions of an array to a lower number.

What is flatten in Javascript?

Flatten means the array which is nested to some level of depth. In Javascript, arrays can be nested with any depth, these arrays can be reformed into a single array, i.e. creating a new array with all the sub-array elements concatenated up to specified depth.

How do you use an array flat?

  1. Use the Array. prototype. flat() method to flat an array with the nested arrays.
  2. Use the depth argument to specify how deep the nested arrays should be flattened. The depth is 1 by default.
  3. The flat() also removes the holes in the array with empty slots.
Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article
Twitter Facebook Pinterest