Answers for "convert query param object javascript to string"

1

object to query string javascript

const queryString = Object.keys(params).map(key => {
  encodeURIComponent(key) + '=' + encodeURIComponent(params[key])
}).join('&');
Posted by: Guest on January-16-2021
2

javascript object to query string

function objectToQueryString(obj) {
  var str = [];
  for (var p in obj)
    if (obj.hasOwnProperty(p)) {
      str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
    }
  return str.join("&");
}

var person = { first_name : "Marty",last_name : "Mcfly"};
var queryString=objectToQueryString(person); //"first_name=Marty&last_name=Mcfly"
Posted by: Guest on August-02-2019

Code answers related to "convert query param object javascript to string"

Code answers related to "Javascript"

Browse Popular Code Answers by Language