Created
April 21, 2020 18:51
-
-
Save meaku/66f70f167641d6618e503eeaadd8cabf to your computer and use it in GitHub Desktop.
something qs.stringify with indice style for UrlSearchParams
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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