---
name: "up.util.flatten"
area: "API"
kind: "JavaScript function"
parent: "up.util module"
url: "https://unpoly.com/api/up.util.flatten"
---
<nav aria-label="Unpoly docs">[All docs](https://unpoly.com/index.md) · [up.util module](https://unpoly.com/api/up.util.md)</nav>

# up.util.flatten(array)

Flattens the given `array` a single depth level.

Will also flatten [array-like](https://unpoly.com/api/List.md) values, like a [`NodeList`](https://developer.mozilla.org/en-US/docs/Web/API/NodeList).

<nav aria-label="Contents">

#### Contents

- [Example](#example)
- [Parameters](#parameters)
- [Return value](#return-value)

</nav>

## Example {#example}

```js
let nested = [1, [2, 3], [4]]
up.util.flatten(nested) // result: [1, 2, 3, 4]
```

---

## Parameters {#parameters}

### array {#array}

(required)

An array which might contain other arrays

Type: [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)

---

## Return value {#return-value}

The flattened array

Type: [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)

