Amit Dhamu

Software Engineer

Get domain without subdomain

If you to retrieve the domain of a URL excluding the subdomain (eg. www), you can use this function

const getDomainWithoutSubdomain = url => {
  const urlParts = new URL(url).hostname.split('.')

  return urlParts
    .slice(-(urlParts.length === 4 ? 3 : 2))


Find a HTML Element With Text

Show Comments

Made with by Amit Dhamu.
© MMXXI. All rights reserved.