Hi @MoshinK786 ,
If you want to merge similar terms in a string, take a look at this test.

I use the replace function to replace the " symbol with empty, then use the split function to separate the strings with commas and turn them into an array, then use the union function to merge the same kind of items in the array, and finally use the join function to convert the merged array into a string.
join(union(split(replace(outputs('Compose'),'"',''),','),split(replace(outputs('Compose'),'"',''),',')),',')
The Result:

If you want to merge similar terms in an array, take a look at this test.

split(replace(replace(string(outputs('Compose')),'["',''),'"]',''),',')
union(outputs('Compose_2'),outputs('Compose_2'))
I use the string function to cast the array to a string(since the replace function can only be used in strings, I convert the array to a string in advance and use the replace function) ,then use the replace function to replace the "[and"] with empty, and then use the split function to convert the strings ABC, ABC, XYZ, DEF, ABC, DEF and DEF to a comma-separated array.

Finally, use the union function to merge similar items in the array.
The Result:

Best Regards,
Sunshine Gu