-3

I want to split an email of user before letter

@

in Javascript especialy in angularJS. for example if its

[email protected]

it will turn into

blabla

can someone give me a simple example to make it? because i must split it from API and store it as localstorage, some of example that i find its use limitTo but can we use it to cut it in specific way from @ until end?

2
  • 6
    String.split() ? Commented Aug 13, 2018 at 9:38
  • yes it seems i can use split to solve it Commented Aug 13, 2018 at 9:52

1 Answer 1

2

Try this str.split()

var email = "[email protected]";
var userName = email.split('@');
console.log(userName[0]);

Or use str.substring()

var userName = email.substring(0, email.indexOf('@'));
console.log(userName);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.