How to remove comma for the last objects in "forloop"

Solved
Tourist
4 0 0

Hello Team,

 

We are trying to remove comma from the last item of the forloop.

 

Present Output: [{item1},{item2},{item3},{item4},]

Desired Output: [{item1},{item2},{item3},{item4}]

 

Attaching the piece of code. Please help me out. Awaiting your reply.

 

array.png

0 Likes

Success.

Astronaut
1088 149 274
{% for line_item in line_items %}
{
//other code
{% unless forloop.last %}
},
{% else %}
}
{% endunless %}
{% endfor %}
If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
1 Like
Tourist
4 0 0

Thanks Ninthony. But how can we implement this using "if condition"

0 Likes

Success.

Astronaut
1088 149 274

It's the same concept just in reverse:

 

{% for line_item in line_items %}
{
//other code
{% if forloop.last %}
}
{% else %}
},
{% endif %}
{% endfor %}
If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
1 Like
Tourist
4 0 0

Thank you so much Ninthony

0 Likes