#Parse, modify and stringify URL query strings

1 messages · Page 1 of 1 (latest)

lucid violet
#

Is there a way to parse & modify query string like this?

# https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/append
const url = new URL('https://example.com?foo=1&bar=2');
const params1 = new URLSearchParams(url.search);
params1.append("q1","2")
console.log(params1.toString()) // "foo=1&bar=2&q1=2"
midnight gazelle
lucid violet
#

yes. check url:decode(value, "UTF-8") only outputs a decoded string, not key/value pairs right?
To do something like, I take it we need to split the decoded string & handle it manually?

let url = new URL('https://example.com?foo=1&bar=2');
let params = new URLSearchParams(url.search);
params.append('foo', 4);
console.log(params.getAll('foo')) //Prints ["1","4"].
lucid violet
#

Parse, modify and stringify URL query strings