# Flatten Array

Flatten array one level deep using lodash _.flatten

> Canonical page: https://elysiatools.com/en/tools/flatten-array

- **Category:** Data Processing

- **Keywords:** array, flatten, nested, lodash, transform

## Overview

Flatten an array one level deep (nesting flattened to a single level).

## Features:
- Accepts nested JSON arrays of any depth
- Flattens only one level of nesting
- Preserves deeper nested structures
- Handles arrays with mixed data types
- Uses lodash _.flatten for reliable array processing

## Examples:
- Input: [1, [2, [3]], 4] → Output: [1, 2, [3], 4]
- Input: [["a", "b"], ["c", "d"]] → Output: ["a", "b", "c", "d"]
- Input: [1, [2, [3, [4]]], 5] → Output: [1, 2, [3, [4]], 5]

## Use Cases:
- **Data Preprocessing**: Reduce one level of nesting in structured data
- **Array Normalization**: Simplify nested array structures
- **Batch Processing**: Prepare nested data for processing
- **Data Transformation**: Convert nested arrays to simpler structures

## Inputs

- **Array Input** (textarea): Enter a valid JSON array with nested elements

## When to use

- When you need to reduce one level of nesting in JSON arrays from APIs or databases.
- For normalizing nested array structures before data analysis or transformation.
- To prepare nested data for batch processing or further computational tasks.

## How it works

- Input a valid JSON array into the text area provided.
- The tool processes the array using the lodash _.flatten function.
- It returns a new array with one level of nesting removed.
- Deeper nested structures are preserved as-is in the output.

## Use cases

- Simplifying nested API responses for frontend development.
- Preprocessing data for machine learning or statistical analysis.
- Normalizing array structures in data pipelines or ETL workflows.

## Frequently asked questions

### What does flattening an array mean?

Flattening reduces the nesting level of an array by one, converting nested arrays into a single-level array where possible.

### Can this tool handle arrays with mixed data types?

Yes, it processes arrays containing numbers, strings, objects, and other arrays without issues.

### Does it flatten all levels of nesting?

No, it only flattens one level deep; deeper nested elements remain unchanged.

### Is the original array modified?

No, the tool returns a new array, leaving the input array untouched.

### What library is used for flattening?

It relies on the lodash library's _.flatten function for consistent and reliable array processing.

## Related tools

- [Flatten Depth Array](https://elysiatools.com/en/tools/flatten-depth-array): Flatten array to specified depth using lodash _.flattenDepth
- [From Pairs](https://elysiatools.com/en/tools/from-pairs): Convert array of key-value pairs to object using lodash _.fromPairs
- [Chunk Array](https://elysiatools.com/en/tools/chunk-array): Split array into chunks of specified size using lodash _.chunk
- [Compact Array](https://elysiatools.com/en/tools/compact-array): Remove falsey values from array using lodash _.compact
- [Drop Items](https://elysiatools.com/en/tools/drop-items): Drop first N items from array using lodash _.drop
- [Drop Right Items](https://elysiatools.com/en/tools/drop-right-items): Drop last N items from array using lodash _.dropRight
- [Drop While](https://elysiatools.com/en/tools/drop-while): Drop items from array while predicate is true using lodash _.dropWhile
- [Fill Array](https://elysiatools.com/en/tools/fill-array): Fill array with value from start to end index using lodash _.fill

## Samples

- [Grafana Advanced Application Samples](https://elysiatools.com/en/samples/grafana-samples): Comprehensive Grafana samples covering advanced dashboard design, alerting configurations, data source integrations, and plugin development
- [QR Code Samples](https://elysiatools.com/en/samples/qrcode-samples): Sample QR code images for testing QR code reading and generation tools
- [D3.js Data Visualization Samples](https://elysiatools.com/en/samples/d3js-data-visualization): Comprehensive D3.js data visualization examples including charts, maps, animations, and interactive visualizations
- [Rome JavaScript Toolchain Samples](https://elysiatools.com/en/samples/rome): Rome JavaScript toolchain examples including configuration, linting, formatting, bundling, and project management
