taking off the http or https off a javascript string

前端 未结 12 1603
面向向阳花
面向向阳花 2020-12-20 11:23

I have the following strings

http://example.com
https://example.com
http://www.example.com

how do i get rid of the http:// or

12条回答
  •  心在旅途
    2020-12-20 12:12

    Assuming there are no double slashes other than the protocol, you could do:

     var url = "https://example.com";
     var noProtocol = url.split('//')[1];
    

提交回复
热议问题