Get the domain of an email address

Take the part after the last @ and lowercase it, for domain checks and grouping.

JavaScript Version 1.0.0 · MIT · by Oveyon · .md

get-the-domain-of-an-email-address.js
function emailDomain(address) { return address.slice(address.lastIndexOf('@') + 1).toLowerCase(); }

Input & expected output

Input

"Ana.Silva@Example.COM"

Expected output

"example.com"

The edge case

Input

"\"ana@team\"@example.com"

Expected output

"example.com"

Know the limits

  • The last @ separates the domain, so a quoted local part containing @ still works. This does not validate the address.
  • Domain names are case-insensitive. Oveyon’s disposable-domain lookup takes a domain like this one, so the full address never leaves your backend.

The function above is the implementation used by the lab. The lab validates JSON types and caps size before execution; include equivalent validation when accepting untrusted input in your application.

Source & maintenance

Written by Oveyon for this edition of 1loc.dev; it is not part of the original collection. Copyright (c) 2026 Oveyon. MIT licensed.

Its file in the public edition: contents/get-the-domain-of-an-email-address.mdx in akamind/1loc, commit 0a77f131b22d. The function above is the implementation the lab runs and the tests exercise; the test suite checks that it is the code that file carries. Read the license.

Local fixture scope · Node.js 22.23.2 · reviewed October 28, 2026. No external service is required.

Keep exploring

Type two or more characters. Try “duplicate”, “webhook” or “retry”.