×

Please give details of the problem

Skip to content

How to create a list from an array

Code:

<#assign my_array = ["Item 1", "Item 2", "Item 3"]> 

<#assign my_list = []> 
<#list my_array as x>
    <#assign my_list = my_list + [{ "label": x, "value": x }]>  
</#list>
${my_list}

Result:

[
    { "label":"Item 1", "value":"Item 1" },
    { "label":"Item 2", "value":"Item 2" },
    { "label":"Item 3", "value":"Item 3" }
]