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 148 views
1 answer 142 views
1 answer 170 views
2 answers 248 views
1 answer 181 views
2 answers 215 views
...