Need help cleaning up this code, which modifies the subdomain.

DeChamp - Jul 10 '19 - - Dev Community

Goal would be to get one subdomain and swap it out for another. I feel there has to be a cleaner way to do this. help me out!

var url = window.location;

// example doamin would have a subdomain so https://auth.domain.ext
var domain = url.host;
var domainParts = domain.split('.');
var mainDomainParts = domainParts.slice(domainParts.length - 2, domainParts.length);
mainDomainParts.unshift('admin');
var adminDomain = mainDomainParts.join('.');
var fullAdminDomain = url.protocol + '//' + adminDomain;
Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player