Check if key exists in array in nunjucks template (Node JS) Check if key exists in array in nunjucks template (Node JS) node.js node.js

Check if key exists in array in nunjucks template (Node JS)


You should be able to do this:

{% if 'add_user' in user_params %}   do stuff in html{% endif %}

For indexOf, I'm not sure that works but even if it did, if zero evaluates to false that's not good either if you're testing the first row. would also need to check > -1


The only way I found is looping through the array like so:

{% for param in user_params %}    {% if param==='add_user' %}        do stuff in html    {% endif %}{% endfor %}

Ugly and full of holes, but will fit most use cases.

You're probably better off making a custom filter