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

```
Try it using [`substring()`](http://www.w3schools.com/jsref/jsref_substring.asp) and [`indexOf()`](http://www.w3schools.com/jsref/jsref_indexof.asp)

```
var name = email.substring(0, email.indexOf("@"));

```