javascript - Trouble removing duplicates from list -


//get email test area  var emaillist = document.getelementbyid("emailtextarea").value; var emaillistarray = emaillist.split("\n");  //remove yahoo , duplicates list  var usernamesarray = emaillistarray.map(function(val, index, arr) {     return val.slice(0, val.indexof('yahoo.com')); }); 

assuming:

emaillistarray = ['123@gmail.com','123@yahoo.com','123@gmail.com','123@hotmail.com'] 

you can this:

var usernamesarray = []; emaillistarray.foreach(function(item) {      if(usernamesarray.indexof(item) < 0 && item.indexof('yahoo.com') < 0) {          usernamesarray.push(item);      } }); 

first condition checks if element in turn not in array of results, second condition checks if element doesn't contain substring yahoo.com, if both true, element added results.

after that, usernamesarray should have:

[ '123@gmail.com', '123@hotmail.com' ] 

Comments

Popular posts from this blog

swift - Button on Table View Cell connected to local function -

dns - Dokku server hosts two sites with TLD's, both domains are landing on only one app -

c# - ajax - How to receive data both html and json from server? -