Skip to content

Instantly share code, notes, and snippets.

@meaku
Created April 21, 2020 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meaku/66f70f167641d6618e503eeaadd8cabf to your computer and use it in GitHub Desktop.
Save meaku/66f70f167641d6618e503eeaadd8cabf to your computer and use it in GitHub Desktop.
something qs.stringify with indice style for UrlSearchParams
function appendObject(params, obj, prefix) {
for (let key of Object.keys(obj)) {
if (typeof obj[key] === "object") {
appendObject(params, obj[key], prefix ? `${prefix}[${key}]` : key);
} else {
params.append(prefix ? `${prefix}[${key}]` : key, obj[key]);
}
}
return params;
}
let params = new URLSearchParams();
params = appendObject(params, {invoice, invoicePosSave});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment