Remove duplicates from an array of objects

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

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.

1 Like