[JavaScript] Extract Only the Domain Part After @ from Email Address

Tadashi Shigeoka ·  Sat, July 15, 2017

I’ll introduce JavaScript code that extracts only the domain part after @ from an email address.

JavaScript

Code to Extract Only the Domain Part After @ from Email Address

Using the String.prototype.split() method, you can extract only the domain part after @ from an email address with the following code:

var emailAddress = '[email protected]';
var emailDomain = emailAddress.split('@')[1];

console.log(emailDomain);
// 'exaple.com'

You could also extract it using regular expressions, but this time I wrote code using the split method, prioritizing clarity.

Reference Information

That’s all from the Gemba.