# Remove duplicates from an array of objects

**URL:** <https://discourse.nodered.org/t/remove-duplicates-from-an-array-of-objects/28013>\
**Category:** General\
**Created:** [8 June 2020 21:07 UTC](https://discourse.nodered.org/t/remove-duplicates-from-an-array-of-objects/28013 "2020-06-08T21:07:26Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![michaelblight](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/michaelblight/32/445_2.png) [@michaelblight](https://discourse.nodered.org/u/michaelblight)\
**Post date:** [9 June 2020 04:17 UTC](https://discourse.nodered.org/t/remove-duplicates-from-an-array-of-objects/28013/2 "2020-06-09T04:17:30Z")

</div>

I would take the lazy approach and use a function node.

```auto
var prev = null;

msg.payload = msg.payload.filter((item) => {
    var keep = (item.x !== prev);
    prev = item.x;
    return keep;
});

return msg;

```

This assumes you only want to dedupe on 'x', and they are all in sequence. You would have to modify it a bit if that's not the case.

---

_[View the full topic](https://discourse.nodered.org/t/remove-duplicates-from-an-array-of-objects/28013)._
