1// example url: https://mydomain.com/?fname=johnny&lname=depp
2const urlParams = new URLSearchParams(window.location.search);
3const firstName = urlParams.get('fname'); // johnny
1serialize = function(obj) {
2 var str = [];
3 for (var p in obj)
4 if (obj.hasOwnProperty(p)) {
5 str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
6 }
7 return str.join("&");
8}
9
10console.log(serialize({
11 foo: "hi there",
12 bar: "100%"
13}));
14// foo=hi%20there&bar=100%25
1//Using query string to concat variable with string
2const txt = "My name is"
3console.log(`${txt} Paul`);