Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Duplicates From Comma Delimited String

How do I remove duplicates from a comma delimited string of integers using jquery/javascript?

My string is: 1,2,2,4,2,4,3,2,3,1,5,5,5,1,1,2

like image 758
Tommy Arnold Avatar asked Sep 11 '26 07:09

Tommy Arnold


1 Answers

For one method, which doesn't demand writing the functionality from scratch or using some other js library check out duck-punching-with-jquery. (look for 'Example 2: $.unique() enhancement')

If you're willing to try some other library, the excellent underscorejs includes a 'uniq' method which accomplishes just what you need.

like image 193
biril Avatar answered Sep 12 '26 20:09

biril



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!