Quantcast
Channel: Mockaroo Community Forum - Latest posts
Viewing all articles
Browse latest Browse all 2665

Iterating through arrays (for loop?)

$
0
0

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?


Viewing all articles
Browse latest Browse all 2665

Trending Articles