To check encode URL in JavaScript you can use the built-in function encode URIComponent(str) and encodeURI(str):-
Use the below-mentioned code:-
var myOtherUrl = "http://example.com/index.html?url=" + encodeURIComponent(myUrl);
Want to become a Web Developer, join Web Development Courses now!