I like to remove an array variable conditions from a query string which will be window.location.search.
- First output
Beforeis the initial string. - Second is after removing
sub - Third still contains
conditions.
How can I get rid of it?
edit The unencoded string is
conditions[0][0][field]=firstname&conditions[0][0][operator]=is&conditions[0][0][value]=John&conditions[1][0][field]=lastname&conditions[1][0][operator]=is&conditions[1][0][value]=Doe
which is needed for the application.
var string = '?page=foo&sub=bar&conditions%5B0%5D%5B0%5D%5Bfield%5D=firstname&conditions%5B0%5D%5B0%5D%5Boperator%5D=is&conditions%5B0%5D%5B0%5D%5Bvalue%5D=John&conditions%5B1%5D%5B0%5D%5Bfield%5D=lastname&conditions%5B1%5D%5B0%5D%5Boperator%5D=is&conditions%5B1%5D%5B0%5D%5Bvalue%5D=Doe';
var params = new URLSearchParams(string);
console.log('Before', params.toString());
params.delete('sub');
console.log('remove sub works', params.toString());
params.delete('conditions');
console.log('conditions still exist', params.toString());
=afterconditionsin the URL.conditionsin your URL - not from the JS perspective. What you have, is parameters namedconditions[0][0][field],conditions[0][0][operator], etc.conditions?conditions- developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/…