Answers for "pass array as query string 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
0

how to send array in query string in javascript

myArray = ['1', '2', '3'];
var arrStr = encodeURIComponent(JSON.stringify(myArray));
window.location = url + '/?id='+id + '&type=' + myArray;
Posted by: Guest on August-18-2021

Code answers related to "pass array as query string javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language