0

The url is something like this

../search/days=4&people=4&stars[]=1&stars[]=2

I want to remove the parameter stars[] which is multiple in my case. I tried using below script but it is removing only 1 instance of the parameter but not all.

var onlyUrl = window.location.href.replace(/&stars\[\]=\d+/, '');

Short & sweet solution is appreciated. Thank you in advance.

dbp
  • 19
  • 1
  • 10

1 Answers1

0

You need to add /g for a global regex

var onlyUrl = window.location.href.replace(/&stars\[\]=\d+/g, '');
Alan Fitzpatrick
  • 181
  • 1
  • 1
  • 10