Detail Data - Variably display content of the detail data

So I am trying to make a variable paragraph with the content from the detail record set.

blah blah blah, @Detail1@ and @Detail2@ and @Detail3@

However there could be any infinite number of detail records per record so this needs to be conditional, how do I go about this, I am new to PP and have been working with Printshop Mail for a number of years.

Thanks

Liam

Think I have answered my own question, is this the best solution:

{
var text=“”;

for (i = 0; i < record.tables["detail"].length; i++) { 
    if(i!=0)
    {text +=" and ";}
    text += record.tables["detail"][i].fields["FirstName"];
}

results.html(text);

}

Alternatively you could use:

var stringbuilder = [];

for(var i in record.tables["detail"]){
    stringbuilder.push(record.tables["detail"][i].fields["FirstName"]);
}

var text = stringbuilder.join(" and ");
results.html(text);

Or use:

var stringbuilder = [];

 for (i = 0; i < record.tables["detail"].length; i++) {
     stringbuilder.push(record.tables["detail"][i].fields["ItemNumber"]);
}

var text = stringbuilder.join(" and ");
results.html(text);

The join() method joins the elements of an array into a string, and returns the string. The elements will be separated by a specified separator. The default separator is comma (,).

Erik