Take the following string as an example:
var string = \"spanner, span, spaniel, span\";
From this string I would like to find the duplicate
// Take the following string var string = "spanner, span, spaniel, span"; var arr = string.split(", "); var unique = []; $.each(arr, function (index,word) { if ($.inArray(word, unique) === -1) unique.push(word); }); alert(unique);
Live DEMO