Answers for "js to query string"

0

javascript object to params string

var queryString = Object.keys(params).map(key => key + '=' + params[key]).join('&');
Posted by: Guest on April-30-2020
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 "Javascript"

Browse Popular Code Answers by Language