remove url parameters with javascript or jquery

mheavers picture mheavers · Jan 10, 2011 · Viewed 137.3k times · Source

I am trying to use the youtube data api to generate a video playlist.

However, the video urls require a format of:

youtube.com/watch?v=3sZOD3xKL0Y

but what the api generates is:

youtube.com/watch?v=3sZOD3xKL0Y&feature=youtube_gdata

So what I need to do is be able to select everything after and including the ampersand(&) and remove it from the url.

Any way to do this with javascript and some sort of regular expression?

Answer

goldylucks picture goldylucks · Jan 5, 2015

What am I missing?

Why not:

url.split('?')[0]