Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

object to query string javascript

const queryString = Object.keys(params).map(key => {
  encodeURIComponent(key) + '=' + encodeURIComponent(params[key])
}).join('&');
Comment

object to query string js

const obj = {foo: "hi there", bar: "100%" };
const params = new URLSearchParams(obj).toString();
Comment

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]
  }
})
);
Comment

PREVIOUS NEXT
Code Example
Javascript :: ternaire js 
Javascript :: document get elements by id js 
Javascript :: findbyid mongoose 
Javascript :: get element by id like javascript 
Javascript :: how to change background color though props 
Javascript :: switch js 
Javascript :: flatten array recursively 
Javascript :: how to check platform in nodejs 
Javascript :: axios send file 
Javascript :: jquery next sibling with class 
Javascript :: random coordinates js 
Javascript :: get all indexes for element in array javascript 
Javascript :: javascript randint 
Javascript :: what is startof() in moment 
Javascript :: javascript multidimensional array foreach 
Javascript :: jQuery hasClass() - check for more than one class 
Javascript :: json data 
Javascript :: javascript select input text on focus 
Javascript :: counts the duplicates in an array using for loop 
Javascript :: moment js between two dates 
Javascript :: print all days names of a month js javascript 
Javascript :: react native run ios 
Javascript :: await in react in function component 
Javascript :: react focus textarea 
Javascript :: javascript convert array to object 
Javascript :: change key name in array of objects javascript 
Javascript :: how to use trim in node js 
Javascript :: state in constructor javascript 
Javascript :: string indexing in js 
Javascript :: run onclick function once 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =