We can collect userid and domain name part of any email address by using JavaScript string function slice and indexOf. We will use indexOf function to find the location of @ symbol ( or char ) present inside the email address. Using this value we will slice the string starting from left side 0 position to collect the user id part of the email address. Here is the code.
var my_email="useridhere@sitename.com"
var ind=my_email.indexOf("@");
var my_slice=my_email.slice(0,ind);
document.write(my_slice);
Now how to collect the domain part from the email address? We will use the string.length to find out the total length of the string and then collect the part of the string starting from the location of (@ +1) till the end of the string. Here is the code.
var my_email="useridhere@sitename.com"
var ind=my_email.indexOf("@");
var my_slice=my_email.slice((ind+1),my_email.length);
document.write(my_slice);
Using substr function
We will use substr function to get userid and domain part. Here is the code
var my_email="useridhere@sitename.com"
var ind=my_email.indexOf("@");
var my_slice=my_email.substr((ind+1));
document.write(my_slice);