arraysconcatenationappendnunjucks

How to concatenate two arrays in nunjucks


I have two arrays, arr1 and arr2. I want to concatenate (append all items if arr2 in arr1) both arrays and store in arr3. How to achieve this with nunjucks?


Solution

  • you can use javascript concat method in the template like:

    {% set arr1 = [1, 2, 3] %}
    {% set arr2 = ["first", "second", "third"] %}
    {% set arr3 = arr1.concat(arr2) %}