<p>I'd probably try to filter those out in your initial query, but if you've already got them, something like this should work:</p>

<pre><code>{% set existingIds = [] %}

{% for event in events %}
    {% if event.id not in existingIds %}
        {{ event.title }}

        {% set existingIds = existingIds|merge([event.id]) %}
    {% endif %}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2016-04-09T02:17:05.237Z
Of course that worked like a charm. Thanks. I tried to close that block on line 7, but the edit had to be 6 characters.
Ben Shoults
CC BY-SA 3.0
2016-04-08T23:46:09.513Z
2016-04-09T06:31:55.410Z
2016-04-09T06:31:55.410Z
Brad Bell
<p>Is it possible to loop through the list of entries and filter out any that have the same ID as any of the other entries (duplicates)? I have a specific case where this is an issue. I want to keep the first entry, but filter out the rest of them. I'm thinking it might work something like this...</p>

<pre><code>  {% for event in events %}
    {% IF FIRST INSTANCE OF ENTRY %}
      {{ event.title }}
    {% endif %}
  {% endfor %}
</code></pre>

<forloop>
Check and remove repeat entries from loop
# Check and remove repeat entries from loop

(Asked by: username_0 on 2016-04-08)

Is it possible to loop through the list of entries and filter out any that have the same ID as any of the other entries (duplicates)? I have a specific case where this is an issue. I want to keep the first entry, but filter out the rest of them. I'm thinking it might work something like this...
  {% for event in events %}
    {% IF FIRST INSTANCE OF ENTRY %}
      {{ event.title }}
    {% endif %}
  {% endfor %}

**Tags:** forloop

---

## 1 answers

### Answer by username_1 on 2016-04-08. Score: 6 | Accepted answer

I'd probably try to filter those out in your initial query, but if you've already got them, something like this should work:
{% set existingIds = [] %}

{% for event in events %}
    {% if event.id not in existingIds %}
        {{ event.title }}

        {% set existingIds = existingIds|merge([event.id]) %}
    {% endif %}
{% endfor %}

> **Comments:**
> **username_0**: Of course that worked like a charm. Thanks. I tried to close that block on line 7, but the edit had to be 6 characters.  

---

