I want to convert the searchParams function into an object? like this =>>>
URLSearchParams { ‘title’ => ‘1’ } to { title : 1 }
I want this to be done for everything in the URLSearchParams, not just one value
i get and push to object like this
const url = { title: "" };
url.title=req.nextUrl.searchParams.get("title");
but i want for any value
2
Answers
There doesn’t appear to be a trivial way to do this, but one could write a function pretty easily to convert a
URLSearchParams
object to a standard object:I think the most straight-forward way would be this: