Iterating through arrays (for loop?)

I’ve imported a dataset of json objects containing name, uuid and slug

I need a comma separated string formed with a random amount of names from the dataset

I created an array of names using “categories[1-5]”. Now i’m trying to concat the array with commas, I did:

str = this[0]
if this[1] then str = concat(str,', ', this[1]) end
if this[2] then str = concat(str,', ', this[2]) end
if this[3] then str = concat(str,', ', this[3]) end
if this[4] then str = concat(str,', ', this[4]) end
str

This works, however i would like to allow my solution to grow in numbers if I end up needing more than 5 names but i can’t figure out how to do a simple for loop. Is it possible?

This would also be something I would like to know how to do, but haven’t been able to figure it out. Every time I try to set up a loop I get syntax errors from the formula

“field”: “error: no implicit conversion of Integer into Array”,