Loop through categories and get bottom-most category for each tree I need to get the last item that don't have a child. So in this case I need 

Mobiltelefoner
Ipad
Køleskab
Vaskemaskine

How to I get the last item that don't have a child without knowing the amount of levels?
Have a look at Craft’s nav tag, which allows to recursively iterate through
an array of element models. Only output the category title if the category has no descendants.

{% nav category in categories %}
    {% if not category.getDescendants().total() %}
        &lt;span&gt;{{ category.title }}&lt;/span&gt;
    {% endif %}

    {% ifchildren %}
        {% children %}
    {% endifchildren %}
{% endnav %}


Another option would be to write a self-calling macro to recursively traverse the tree.

{% macro getBottomMostElements(elements) %}
    {% import _self as self %}

    {% for element in elements %}
        {% if element.getDescendants().total() %}
            {{ self.getBottomMostElements(element.getDescendants(1)) }}
        {% else %}
            &lt;span&gt;{{ element.title }}&lt;/span&gt;
        {% endif %}
    {% endfor %}
{% endmacro %}

{% import _self as macros %}
{{ macros.getBottomMostElements(categories.level(1)) }}