Answers for "how to convert array to query in javascript"

2

javascript array 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 "how to convert array to query in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language