How to remove `&` sign and all text after that from url

  • A+

I have this url

Here am getting sys_id two times with different parameters. So I need to remove the second & sign and all text after that.

I tried this


I am sure it doesn't workout. Can anyone provide some better solution?


Firstly, you should split the string into an array then use slice to set the starting index number of the element which is 2 in your case and then join the array again into the string.

Read more about these methods JavaScript String split() Method, jQuery slice() Method and JavaScript Array join() Method

var url = '';  url = url.split("&").slice(0,2).join("&"); console.log(url);


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: