Horje
js query string from object Code Example
js query string from object
const params = {lat: 35.681236, lng: 139.767125, zoom: 15};
new URLSearchParams(params).toString();
// "lat=35.681236&lng=139.767125&zoom=15"

// OR

const queryString = Object.keys(params).map(key => {
  encodeURIComponent(key) + '=' + encodeURIComponent(params[key])
}).join('&');
object to query string javascript
const queryString = Object.keys(params).map(key => {
  encodeURIComponent(key) + '=' + encodeURIComponent(params[key])
}).join('&');
object to query string js
const obj = {foo: "hi there", bar: "100%" };
const params = new URLSearchParams(obj).toString();
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"
javascript object to query string
queryBuilder = function(obj, prefix) {
  var str = [],
    p;
  for (p in obj) {
    if (obj.hasOwnProperty(p)) {
      var k = prefix ? prefix + "[" + p + "]" : p,
        v = obj[p];
      str.push((v !== null && typeof v === "object") ?
        serialize(v, k) :
        encodeURIComponent(k) + "=" + encodeURIComponent(v));
    }
  }
  return str.join("&");
}

console.log(
serialize({
  foo: "hi there",
  bar: {
    blah: 123,
    quux: [1, 2, 3]
  }
})
);




Javascript

Related
javascript window.location new tab Code Example javascript window.location new tab Code Example
remove all options from select jquery Code Example remove all options from select jquery Code Example
fecth post json Code Example fecth post json Code Example
jquery wait n seconds Code Example jquery wait n seconds Code Example
remove special characters from string javascript Code Example remove special characters from string javascript Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
12