Well, according to the documentation for slice, using a negative index will allow you start indexing from the end of the array rather than the beginning.
So domainParts.slice(domainParts.length - 2, domainParts.length) is equivalent to domainParts.slice(-2).
Another thing is that since admin is a constant, you can add that when you are concatenating the string rather than manipulating the array.
varurl=window.location;// example domain would have a subdomain so https://auth.domain.extvardomain=url.host;varsubdomain='admin';varmainDomain=domain.split('.').slice(-2).join('.');varfullAdminDomain=url.protocol+'//'+subdomain+'.'+mainDomain;
Just a coder and a dad. I love my family and I love to code!!!! started coding at 11, so I have 25 years under my belt. Still love learning about it every day. Black lives matter!
Well, according to the documentation for slice, using a negative index will allow you start indexing from the end of the array rather than the beginning.
So
domainParts.slice(domainParts.length - 2, domainParts.length)
is equivalent todomainParts.slice(-2)
.Another thing is that since admin is a constant, you can add that when you are concatenating the string rather than manipulating the array.
Array.prototype.slice
aww yes! nice!