Can URLSearchParams get param case insensitive?

Viewed 3046

Can URLSearchParams somehow find param and not be case senstive? For example in query I have ?someParam=paramValue, so when I have URLSearchParams.get("someparam") will it find paramValue?

1 Answers

URLSearchParams keys are case sensitive. I don't see any suggestion in the MDN docs or specification to suggest a flag controlling that behavior or an alternative method, etc.

It's quite straightfoward to convert all the names to lower case in a new URLSearchParams object, though:

const params = new URLSearchParams(
    "?someParam=paramValue"
);
// Doesn't work
console.log(params.get("someparam"));
// Create the new one
const newParams = new URLSearchParams();
for (const [name, value] of params) {
    newParams.append(name.toLowerCase(), value);
}
// Works
console.log(newParams.get("someparam"));

Related