JSFiddle - React, Tailwind, and code Playground
HTML
<div id="input">
<h1>Input</h1>
</div>
<div id="output">
<h1>Becomes</h1>
</div>
JavaScript
// Take the following string
var string = "spanner, span, spaniel, span";
$('#input').append(string);
// Find the duplicates
// Remove the duplicate, leaving a single occurance of the word in place
// Output the following
var uniqueList=string.split(',').filter(function(allItems,i,a){
return i==a.indexOf(allItems);
}).join(',');
$('#output').append(uniqueList);