---
name: "List"
area: "API"
kind: "class"
parent: "API reference"
url: "https://unpoly.com/api/List"
---
<nav aria-label="Unpoly docs">[All docs](https://unpoly.com/index.md) · [API reference](https://unpoly.com/api.md)</nav>

# `List`

The Unpoly documentation uses the term `List` to refer to an array-like value.

There is no actual `List` class. Instead, that term refers to an abstract interface for objects that have a `{ length }` property and allow random access to an indexed element:

```js
list[2] // result: 'hello'
list.length // result: 10
```

You can also use them in a `for` loop:

```js
for (let element of list) {
  console.log(element)
}
```

Whether a list supports additional utilities like [`forEach()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach) or [`map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) depends on the specific type of the list value.

## Common list types {#common-list-types}

Common types of array-like values include:

- [`Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)
- [`NodeList`](https://developer.mozilla.org/en-US/docs/Web/API/NodeList)
- [`HTMLCollection`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCollection)
- [`arguments`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments) object
- [jQuery object](https://learn.jquery.com/using-jquery-core/jquery-object/)

## Converting lists to arrays {#convert-to-array}

Sometimes you may want to convert an array-like value into an actual [`Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) so you can call methods like [`map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) or [`flat()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat).

One way to do this is to spread the array-like value into a new array:

```js
let array = [...list]
```

One drawback of spreading is that it always creates a new array, even if the given `list` is already an [`Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array). To only convert non-[`Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) values, use [`up.util.toArray()`](https://unpoly.com/api/up.util.toArray.md):

```js
let array = up.util.toArray(list)
```

