Comparing two arrays, checking for matching values

I have a repeater field which allows user to add text.

I’ve created an array which stores all these repeater values into an array called topics.

{% set topics = [] %}

<!-- append topics from repeater to array -->
{% for item in module.add_topics.topics %}
 {% set topic_option = item|striptags %}
 {% do topics.append( topic_option ) %}
{% endfor %}

<!-- dumping data 
{{ topics }}

[Data, Accounting, Insight]
--> 

The above is basically a predefined list. I now want to compare values in the above array to all blog tags that exist.

Demo:

{% set all_tags = blog_topics('default' , 250) %}

{{ all_tags }}

<!-- above prints: [Accounting, Press, Data] -->

So from the above two arrays, Data and Accounting are in both. I now want to create another array which has these matching values.

How can I go about this?

Hey @Amit_95

Thank you for sharing this. I’ll tag a few experts that can share their expertise.

Hey @Kevin-C @alyssamwilie @John any tips you can share with @Amit_95?

Thank you :slightly_smiling_face:

Sharon

Hey @Amit_95

Have you tried “intersect”?

Using that filter it should return a dict with the matching objects.

{{ topics|intersect(all_tags) }}