jQuery.param() takes an array of key-value pairs, and turns it into a string you can use as a query string in HTML requests. For example,
a = {
userid:1,
ES6 gives us some nice primitives:
// Function that parses an object of string key/value params to build up
// a string of url params
// requires an object with no nested values
export function parseUrlParams(urlParams) {
const joinByEquals = (pair) => pair.join('=')
const params = Object.entries(urlParams).map(joinByEquals).join('&')
if (params) {
return `?${params}`
} else {
return ''
}
}
See it in action here: https://www.webpackbin.com/bins/-KnpOI6hb1AzTDpN3wS7