With javascript, how do we remove the @gmail.com or @aol.com from a string so that what only remains is the name? 

```
var string = "johndoe@yahoo.com";

```

Will be just "johdoe"? I tried with split but it did not end well. thanks.
['https://Stackoverflow.com/questions/18371339', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2522342/']
And another alternative using [split](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split):

```
var email = "john.doe@email.com";
var sp = email.split('@');

console.log(sp[0]); // john.doe
console.log(sp[1]); // email.com

```
As shown in [How to remove or get domain name from an e-mail address in Javascript?](https://www.4codev.com/javascript/how-to-remove-or-get-domain-name-from-an-e-mail-address-in-javascript-idpx2198110465829791878.html), you can do it using the following code:

```
const getDomainFromEmail = email => {
  let emailDomain = null;
  const pos = email.search('@'); // get position of domain
  if (pos > 0) {
    emailDomain = email.slice(pos+1); // use the slice method to get domain name, "+1" mean domain does not include "@"
  }
  return emailDomain;
 };

```

```
const yourEmail = "jonth.nt49@4codev.com"
 console.log(getDomainFromEmail(yourEmail));
 // result : 4codev.com

```