Categories
JavaScript Answers

How to Convert JavaScript Object to URL Parameters?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *