Sometimes, we want to pass a URL with multiple parameters into a URL with JavaScript.
In this article, we’ll look at how to pass a URL with multiple parameters into a URL with JavaScript.
How to pass a URL with multiple parameters into a URL with JavaScript?
To pass a URL with multiple parameters into a URL with JavaScript, we use the encodeURIComponent
method.
For instance, we write
const encodedParam = encodeURIComponent(
"www.foobar.com/?first=1&second=12&third=5"
);
to call encodeURIComponent
with the URL string.
Then URL encoded string is returned.
Conclusion
To pass a URL with multiple parameters into a URL with JavaScript, we use the encodeURIComponent
method.