Applescript add coma between list item and return as text

applescriptjavascriptjavascript-automationsafari

Im trying to get some value from safari and return them as text in this format

Val1, Val2, val3,

set x to ", "
set myRARText to {}
tell application "Safari" to tell document 1 to tell (do JavaScript "
    [...new Set( document.getElementsByClassName('subtitle') )]
    .map( x => x.innerText.trim() );") ¬
    to set rarOrder to every text

repeat with each from 1 to count of items of rarOrder
    set rarOrder to rarOrder & x

end repeat

set the clipboard to rarOrder as text

With the code I wrote, I'm getting instead

Val1Val2val3 , , ,

how can I get the result as text and in the correct format?

Best Answer

Found the answer using text delimiters

set saveTID to text item delimiters
set text item delimiters to ", "
set Final to rarOrder as text
set text item delimiters to saveTID


set the clipboard to Final