I'm getting a query params object that may look like this:
const queryParams = { status: 'Online', name: 'Jeff', age: '35' }
I need to create a query params string out of it,
Example return value would be:
?status=Online&name=Jeff&age=35&
I wrote this function:
const getParams = (queryParams) => {
let str = '?'
for (key in queryParams) {
if (queryParams[key]) {
str+= `${key}=${queryParams[key]}&`
}
}
return str
};
Is there a shorter/better way to do it than this function?