How to Remove http:// or https:// from a URL in JavaScript

1 Answer

0 votes
function removeHttp_s(url) {
  	return url.replace(/^https?:\/\//, '');
}


console.log(removeHttp_s('https://commentsinfo.com'));

console.log(removeHttp_s('http://commentsinfo.com'));

  
  
  
  
/*
run:
  
"commentsinfo.com"
"commentsinfo.com""
  
*/

 



answered Apr 27, 2022 by avibootz
edited Apr 27, 2022 by avibootz

Related questions

1 answer 150 views
1 answer 144 views
1 answer 172 views
2 answers 252 views
1 answer 184 views
2 answers 217 views
...