How to pass the iterated data inside the for loop of Hubspot's HUBL.

Normally the variable inside the loop was carried over after the loop and can be used anytime you like in any line of the code after the loop but not in hubspot. After the loop all variable inside it, is still undefined outside.
E.g.


{% set varname = "hello" %}
{% set array = ["world","hubspot"] %}
{% for item in array %}
{% set varname = varname~item %}
{% endfor %}

{# varname will printout hello instead of helloworldhubspot #}
{{ varname }}

There was still a way to how to carry the data from the loop though we need an extra variable where to write it while the loop is iterating. Sounds strange right? But we have no other choice. Whatever it is, at least it does what we want.

Here's an example code:


{# this is the additional variable where we are going to write the data while iterating the loop #}
{% set varholder = [] %}

{% set varname = "hello" %}
{% set array = ["world","hubspot"] %}

{% for item in array %}
{% do varholder.append(item) %}
{% endfor %}

{{ varname~varholder|join("") }}

That's it! Happy Hubspoting! :)