An object containing key-value pairs to be converted into a query string. The values can be of type string, number, or boolean.
OptionalsearchParams: null | URLSearchParamsAn optional instance of URLSearchParams to start with. If not provided, a new instance will be created.
Optionalencode: booleanAn optional boolean indicating whether to encode the resulting query string using encodeURIComponent. Defaults to false.
The generated query string.
const params = { name: 'John', age: 30, active: true };
const queryString = createQueryString(params);
console.log(queryString); // Output: "name=John&age=30&active=true"
const searchParams = new URLSearchParams('existing=param');
const queryStringWithSearchParams = createQueryString(params, searchParams);
console.log(queryStringWithSearchParams); // Output: "existing=param&name=John&age=30&active=true"
const encodedQueryString = createQueryString(params, null, true);
console.log(encodedQueryString); // Output: "name%3DJohn%26age%3D30%26active%3Dtrue"
Creates a query string from the given parameters.