DEV Community

Discussion on: How to get Query String Parameters in Javascript - 2019

Collapse
 
daviddalbusco profile image
David Dal Busco • Edited

Is there any particular reason why you don't use the Web Apis URL or URLSearchParams ?

Collapse
 
yalme profile image
Артём Пешков

IE 11 support only with polyfill.

Collapse
 
ganeshmani profile image
GaneshMani

Though URLSearchParams works well for the usecase. i wanted to get all the query strings from the url which is difficult in URLSearchParams(from what i know). i wanted to write a custom function that i can use to get all query strings in the url.

Collapse
 
daviddalbusco profile image
David Dal Busco

Didn't tried out but it seems that URLSearchParams offers iterator to get all query strings.

From the doc:

URLSearchParams.entries()
Returns an iterator allowing iteration through all key/value pairs contained in this object.

URLSearchParams.keys()
Returns an iterator allowing iteration through all keys of the key/value pairs contained in this object.

Found out an example too: davidwalsh.name/query-string-javas...

That being said, the good point of your method is that it is compatible with Internet Explorer 😉

Thread Thread
 
ganeshmani profile image
GaneshMani

Cool.. Thanks for the update. i will add this in article.