---
name: "up.util.map"
area: "API"
kind: "JavaScript function"
parent: "up.util module"
url: "https://unpoly.com/api/up.util.map"
---
<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.map(list, block)

Maps all items in a [list](https://unpoly.com/api/List.md) to a new array of items.

<nav aria-label="Contents">

#### Contents

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

</nav>

## Example {#example}

The given mapping function will be called for each element in the list:

```js
up.util.map(['apple', 'cherry'], (str) => str.length) // result: [5, 6]
```

You can also pass a property name as a string, which will be collected from each item in the list:

```js
up.util.map(['apple', 'cherry'], 'length') // result: [5, 6]
```

---

## Parameters {#parameters}

### list {#list}

(required)

Type: [List](https://unpoly.com/api/List.md) | Iterator

### block {#block}

(required)

A function that will be called with each element and (optional) iteration index.

You can also pass a property name as a string, which will be collected from each item in the list.

Type: Function(element, index): any | string

---

## Return value {#return-value}

A new array containing the result of each function call.

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

