Rahul Nagrale Rahul Nagrale -4 years ago 95
Javascript Question

Check if URL has repeating strings and remove them if any?

I am looking for the way to remove the duplicate string from any url in


example url: http://localhost:33224/abc/abc/xyz.xml

Can anyone here please advise how to remove the duplicate strings from any url using

Answer Source

var url="http://localhost:33224/abc/abc/xyz.xml";

var arr=url.split('/');
var newArr=[];
var newUrl='';
if($.inArray(item,newArr) == -1)

newUrl += item+'/';

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download