Take the following string as an example:
var string = \"spanner, span, spaniel, span\";
From this string I would like to find the duplicate
below is an easy to understand and quick code to remove duplicate words in a string:
var string = "spanner, span, spaniel, span";
var uniqueListIndex=string.split(',').filter(function(currentItem,i,allItems){
return (i == allItems.indexOf(currentItem));
});
var uniqueList=uniqueListIndex.join(',');
alert(uniqueList);//Result:spanner, span, spaniel
As simple as this can solve your problem. Hope this helps. Cheers :)