> For the complete documentation index, see [llms.txt](https://conductor.js.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://conductor.js.org/api-reference/mergeby.md).

# mergeBy

{% hint style="info" %}
Available since v1.4.0
{% endhint %}

### description

`mergeBy` works like [`merge`](/api-reference/merge.md), but uses an additional parameter (`getter`) to retrieve the value used for comparison. This additional parameter can be provided as a `Function`, or a `String` in which case mergeBy will retrieve the value associated to the provided key.

### examples

#### providing a key name as a string

```javascript
import { mergeBy } from 'conductor'

const arr1 = [{ id: 1, name: 'Anakin' }]
const arr2 = [{ id: 1, name: 'Darth Vader', side: 'dark' }]

mergeBy('id', obj1, obj2) // [{ id: 1, name: 'Darth Vader', side: 'dark' }]
mergeBy('name', obj1, obj2)
// [
//    { id: 1, name: 'Anakin' },
//    { id: 1, name: 'Darth Vader', side: 'dark' }
// ]
```

#### providing a function

```javascript
import { get, mergeBy } from 'conductor'

const arr1 = [{ id: 1, name: 'Anakin' }]
const arr2 = [{ id: 1, name: 'Darth Vader', side: 'dark' }]

mergeBy(get('id'), obj1, obj2) // [{ id: 1, name: 'Darth Vader', side: 'dark' }]
mergeBy(get('name'), obj1, obj2)
// [
//    { id: 1, name: 'Anakin' },
//    { id: 1, name: 'Darth Vader', side: 'dark' }
// ]
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://conductor.js.org/api-reference/mergeby.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
