1const params = {lat: 35.681236, lng: 139.767125, zoom: 15};
2new URLSearchParams(params).toString();
3// "lat=35.681236&lng=139.767125&zoom=15"
4
5// OR
6
7const queryString = Object.keys(params).map(key => {
8 encodeURIComponent(key) + '=' + encodeURIComponent(params[key])
9}).join('&');
1const params = {foo:"Hi", bar:"there"}
2const queryString = new URLSearchParams(params).toString();
3
4console.log(queryString);
5
1const queryString = Object.keys(params).map(key => {
2 encodeURIComponent(key) + '=' + encodeURIComponent(params[key])
3}).join('&');
1var queryString = Object.keys(params).map(key => key + '=' + params[key]).join('&');
1function objectToQueryString(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
10var person = { first_name : "Marty",last_name : "Mcfly"};
11var queryString=objectToQueryString(person); //"first_name=Marty&last_name=Mcfly"
1 const queryString = new URLSearchParams(props.location.search);
2//or
3var queryString = Object.keys(params).map(key => key + '=' + params[key]).join('&');
4//Extracting query String key value pairs
5for (let param of queryString.entries()) {
6 console.log(param);
7}