loading
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const getQueryParams = (url) => {
	let queryParams = {};
  //create an anchor tag to use the property called search
	let anchor = document.createElement('a');
  //assigning url to href of anchor tag
	anchor.href = url;
  //search property returns the query string of url
	let queryStrings = anchor.search.substring(1);
	let params = queryStrings.split('&');

	for (var i = 0; i < params.length; i++) {
		var pair = params[i].split('=');
		queryParams[pair[0]] = decodeURIComponent(pair[1]);
	}
	return queryParams;
};



getQueryParams('http://another-example.com?example=something&data=13');




// var getQueryParams = ( params, url ) => {
  
//   let href = url;
//   //this expression is to get the query strings
// 	let reg = new RegExp( '[?&]' + params + '=([^&#]*)', 'i' );
// 	let queryString = reg.exec(href);
// 	return queryString ? queryString[1] : null;
// };

// getQueryParams('data','http://another-example.com?example=something&data=13');
node v10.16.0