How to Convert JavaScript Object to URL Parameters?

Sometimes, we want to convert JavaScript object to URL parameters.

In this article, we’ll look at how to convert JavaScript object to URL parameters.

Convert JavaScript Object to URL Parameters

To convert JavaScript object to URL parameters, we can use the jQuery.params method.

For instance, we write:

const params = {
  width: 1000,
  height: 800
};
const str = jQuery.param(params);
console.log(str);

We have the params object with the width and height properties.

Then we call jQuery.params method with the params object as its argument.

And then we assigned the returned query string to str.

From the console log, we should see that str is 'width=1000&height=800'.

Conclusion

To convert JavaScript object to URL parameters, we can use the jQuery.params method.