I’ve got some code where I need to check if a variable has http:// or https:// and if not, add http:// to the beginning of the var. I have tried some solutions online, but I wasn’t able to get them to work. Could someone let me know how I could add this function? Here’s my code:
//search shorthand
const params = new URLSearchParams(window.location.search)
//find url param from window location and make variable
var url = params.get('url')
//decode url
var url = atob(url);
//this is where I want to do the check and possibly add the http://
//alert the result
alert(url);
Also, if there are any best practices I should be following, please let me know how I can improve my code. Thanks!