or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-lodash--flattendeep

The modern build of lodash's flattenDeep utility function that recursively flattens nested arrays to any depth.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/lodash.flattendeep@3.0.x

To install, run

npx @tessl/cli install tessl/npm-lodash--flattendeep@3.0.0

index.mddocs/

lodash.flattendeep

lodash.flattendeep provides a standalone implementation of lodash's flattenDeep utility function that recursively flattens nested arrays to any depth. It offers a simple API that takes an array as input and returns a new flattened array, making it ideal for data processing scenarios where nested array structures need to be simplified.

Package Information

  • Package Name: lodash.flattendeep
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install lodash.flattendeep

Core Imports

var flattenDeep = require('lodash.flattendeep');

For ES modules:

import flattenDeep from 'lodash.flattendeep';

Basic Usage

var flattenDeep = require('lodash.flattendeep');

// Flatten a deeply nested array
var nestedArray = [1, [2, 3, [4]]];
var result = flattenDeep(nestedArray);
console.log(result);
// => [1, 2, 3, 4]

// Works with any depth of nesting
var deeplyNested = [1, [2, [3, [4, [5]]]]];
var flattened = flattenDeep(deeplyNested);
console.log(flattened);
// => [1, 2, 3, 4, 5]

// Handles empty arrays and mixed types
var mixedArray = [1, [], [2, [3, []]], 4];
var mixedResult = flattenDeep(mixedArray);
console.log(mixedResult);
// => [1, 2, 3, 4]

Capabilities

Array Flattening

Recursively flattens a nested array to any depth, returning a new flat array with all nested elements.

/**
 * Recursively flattens a nested array.
 * 
 * @param {Array} array The array to recursively flatten.
 * @returns {Array} Returns the new flattened array.
 */
function flattenDeep(array);

Parameters:

  • array (Array): The array to recursively flatten. Can be null, undefined, or an empty array.

Returns:

  • (Array): Returns the new flattened array. Returns an empty array if the input is falsy or empty.

Behavior:

  • Recursively processes nested arrays to any depth
  • Preserves the order of elements as they appear when traversed depth-first
  • Returns a new array without modifying the original
  • Handles null and undefined inputs by returning an empty array
  • Preserves non-array elements as-is in their flattened position

Usage Examples:

var flattenDeep = require('lodash.flattendeep');

// Basic nested array
flattenDeep([1, [2, 3, [4]]]);
// => [1, 2, 3, 4]

// Deep nesting
flattenDeep([1, [2, [3, [4, [5, 6]]]]]);
// => [1, 2, 3, 4, 5, 6]

// Mixed types
flattenDeep([1, ['a', [true, [null]]]]);
// => [1, 'a', true, null]

// Empty arrays
flattenDeep([[], [1, []], [2]]);
// => [1, 2]

// Null/undefined input
flattenDeep(null);
// => []

flattenDeep(undefined);
// => []

// Empty array
flattenDeep([]);
// => []