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

Creates an object from the given array and mapping function.

## Example {#example}

The mapping function is called with each array element. It must return a tuple of the object key and value:

```js
up.util.mapObject(['alice', 'bob'], function(element) {
  return [element.toUpperCase(), element.length]
})
// result: { ALICE: 5, BOB: 3 }
```

---

## Parameters {#parameters}

### array {#array}

(required)

The array from which to create an object.

Each array element will become a property of the created object.

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

### mapping {#mapping}

(required)

A function that is called with each array element.

It must return a tuple of the object key and value.

Type: Function(element): Pair<string, any>

