DEV Community

Discussion on: A better way to add URL params

Collapse
 
aminnairi profile image
Amin

Hi there, interesting article, thanks for sharing!

Did you know that there is a native object to handle url queries in JavaScript (Browser)?

"use strict";

const urlSearchParams = new URLSearchParams();

urlSearchParams.append("color", "yellow");
urlSearchParams.append("form", "circle");
urlSearchParams.append("keywords", "young kids playground");

console.log(urlSearchParams.toString());
// color=yellow&form=circle&keyword=young+kids+playground
Collapse
 
rrjoson profile image
RR Joson

Hi Amin!

Yeah, based from caniuse, IE and other Chinese browsers do not support it.

So maybe it depends on your target audience if you'll use URLSearchParams