Get the domain name of the subdomain Javascript

后端 未结 5 781
再見小時候
再見小時候 2020-12-05 07:15

How i can get the domain name example.com from the set of possible subdomains sub1.example.com sub2.example.com sub3.example.com

5条回答
  •  甜味超标
    2020-12-05 07:30

    This is faster

    const firstDotIndex = subDomain.indexOf('.');
    const domain = subDomain.substring(firstDotIndex + 1);
    

提交回复
热议问题