1const urlParams = new URLSearchParams(window.location.search);
2const myParam = urlParams.get('myParam');
1function getUrlParameter(name) {
2 name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
3 var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
4 var results = regex.exec(location.search);
5 return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
6};
1const querystring = require('querystring');
2const url = "http://example.com/index.html?code=string&key=12&id=false";
3const qs = "code=string&key=12&id=false";
4
5console.log(querystring.parse(qs));
6// > { code: 'string', key: '12', id: 'false' }
7
8console.log(querystring.parse(url));
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`);