VOOZH about

URL: https://www.geeksforgeeks.org/javascript/lodash-_-flatten-method/

⇱ Lodash _.flatten() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Lodash _.flatten() Method

Last Updated : 2 Sep, 2024

Lodash _.flatten() method is used to flatten the array to one level deep and it returns a new flattened array.

Syntax:

_.flatten( array );

Parameter:

  • array that holds a simple array or array of arrays.

Return Value:

  • The return type of this function is an array.

Example 1: In this example, er are flattening the array to a single level by the use of the _.flatten() method.

Output:

👁 Image

Example 2: In this example, er are flattening the array of object to a single level by the use of the _.flatten() method.

Output:

👁 Image

Example 3: In this example, er are flattening the empty array to a single level by the use of the _.flatten() method.

Output:

👁 Image
Comment