Using a variable with array of ElementIds to use in craft.entries.id I want to show entries according to an array.

This is my code:

            {% set navsubids = craft.amNav.getNavRaw("hoofdnavigatie", {startFromId:25})  %}
            {% set navsubidarray = [] %}

            {% for navsubid in navsubids %}
                    {% set navsubidarray = navsubidarray|merge([navsubid.elementId]) %}
            {% endfor %}

            {% set navsubidarray = navsubidarray|join(', ') %}

            {{ navsubidarray }}&lt;br&gt;

            {% for entry in craft.entries.id('{{ navsubidarray }}') %}
                {{ entry.title }}&lt;br&gt;
            {% endfor %}


The variable gives back that what I need (18, 17, 19, 4, 20, 21, 22, 23) but the for entry loop isn't returning anything.
I'm not sure where you're getting the id's from but you will need to pass an array into craft.entries.id so try:

{% set navsubids = craft.amNav.getNavRaw("hoofdnavigatie", {startFromId:25})  %}

{% set navsubidarray = [] %}

{% for navsubid in navsubids %}
  {% set navsubidarray = navsubidarray|merge([navsubid.elementId]) %}
{% endfor %}

{% for entry in craft.entries.id( navsubidarray ) %}
  {{ entry.title }}&lt;br&gt;
{% endfor %}


When you used {% set navsubidarray = navsubidarray|join(', ') %} you were creating a string of the values in the array.