# diff-arrays-of-objects

> Compare two arrays of objects, finding added, removed, updated and identical objects. Details the differences between updated objects.

Latest version **1.1.12** (published 2026-09-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install diff-arrays-of-objects
pnpm add diff-arrays-of-objects
yarn add diff-arrays-of-objects
bun add diff-arrays-of-objects
```

## Health

**Score 55/100 (C)** — status: active.

Positive: no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 1.1.12 |
| Published | 2026-09-03 |
| First published | 2018-05-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 8 |
| Dependencies | 2 |
| Unpacked size | 9.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 22 |
| Author | Malcolm van Raalte |
| Maintainers | malcolmvr |
| Keywords | added, array, compare, deep, delta, diff, difference, object, removed, updated, objects |

## Links

- npm: https://www.npmjs.com/package/diff-arrays-of-objects
- Repository: https://github.com/malcolmvr/diff-arrays-of-objects
- Issues: https://github.com/malcolmvr/diff-arrays-of-objects/issues
- npm.io page: https://npm.io/package/diff-arrays-of-objects

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) 4
- [deep-diff](https://npm.io/package/deep-diff.md) ^1.0.2

## Recent versions

- 1.1.12 (latest) — 2026-09-03
- 1.1.11 — 2026-08-19
- 1.1.10 — 2026-04-14
- 1.1.9 — 2021-05-17
- 1.1.8 — 2021-03-31
- 1.1.7 — 2020-07-20
- 1.1.6 — 2020-04-07
- 1.1.5 — 2019-10-04
- 1.1.4 — 2019-07-11
- 1.1.3 — 2019-06-05
- 1.1.2 — 2018-10-13
- 1.1.1 — 2018-06-08
- 1.1.0 — 2018-05-22
- 1.0.0 — 2018-05-21

## README

# diff-arrays-of-objects

> Compare two arrays of objects, finding added, removed, updated and identical objects. Details the differences between updated objects.

## Install

```bash
$ npm install diff-arrays-of-objects --save
```
## Usage

```js
const diff = require('diff-arrays-of-objects');
var result = diff(
  [
    {id: 1, name: 'a'},
    {id: 2, name: 'b'},
    {id: 3, name: 'c'},
    {id: 4, name: 'd'},
    {id: 5, name: 'e'}
  ],
  [
    {id: 1, name: 'a'},
    {id: 2, name: 'z'},
    {id: 7, name: 'e'}
  ],
  'id'
);

console.log(result)
// {
//   added: [
//     { id: 7, name: 'e' }
//   ],
//   removed: [
//     { id: 3, name: 'c' },
//     { id: 4, name: 'd' },
//     { id: 5, name: 'e' }
//   ],
//   updated: [
//     { id: 2, name: 'z' }
//   ],
//   same: [
//     { id: 1, name: 'a' }
//   ]
// }
```

## API

### diff-arrays-of-objects (first, second, idField, [options])

#### first

*Required*<br>
Type: `array`

First array to be compared.

#### second

*Required*<br>
Type: `array`

Second array to be compared.

#### idField

*Required*<br>
Type: `string`

The id field that is used to compare the arrays. Defaults to 'id'.

#### options

Type: `object`

```js
{
  compareFunction: <Func> // defaults to lodash's isEqual; must accept two parameters (o1, o2)
  updatedValues: <Number> // controls what gets returned in the "updated" results array:
                          // diff.updatedValues.first (1): the value from the first array
                          // diff.updatedValues.second (2): the value from the second array (default)
                          // diff.updatedValues.both (3): both values, as an array [first, second]
                          // diff.updatedValues.bothWithDeepDiff (4): both values, plus the results of the deep-diff module; [first, second, deep-diff]
}
```

Examples:

```js
const diff = require('diff-arrays-of-objects');
const first = [{ id: 1, letter: 'a' }];
const second = [{ id: 1, letter: 'b' }];

const result = diff (first, second, idField, { updatedValues: diff.updatedValues.first });
// result.updated is [{ id: 1, letter: 'a' }]

const result = diff (first, second, idField, { updatedValues: diff.updatedValues.second });
// result.updated is [{ id: 1, letter: 'b' }]

const result = diff (first, second, idField, { updatedValues: diff.updatedValues.both });
// result.updated is [{ id: 1, letter: 'a' }, { id: 1, letter: 'b' }]

const result = diff (first, second, idField, { updatedValues: diff.updatedValues.bothWithDeepDiff });
// result.updated is [{ id: 1, letter: 'a' }, { id: 1, letter: 'b' }, { kind: 'E', path: ['letter'], lhs: 'a', rhs: 'b' }]
```

See [deep-diff](https://github.com/flitbit/diff) for more info on deep-diff results

## License

MIT

---
_Source: https://npm.io/package/diff-arrays-of-objects · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
