Skip to content
Advertisement

Javascript arrays email substring into full name, firstname and lastname

      I know my questions are similar to other questions but I could not figure it. 

I am practicing javascript. I have arrays of emails. from that email I want to get three out puts of strings fullname, firstname and lastname inside one map function. I can able to get output first name by reading one stack-overflow questions. I am able get full name by I get output john.doe, I want johndoe. Could not figure it out last name doe.

My example email address is like this: john.doe@co.uk

My expected output is

firstname: ‘john’

fullname: johndoe

lastname: doe

This is my code

const Names = (emails) => {
  emails.map(i => {
    console.log("firstname", i.substring(0, i.indexOf(".")));
    console.log("fullname", i.substring(0, i.lastIndexOf("@")));
    console.log("lastname");
  })
};

Names(emails)

const emails = [
  "peter.pittman@taitos.com",
  "ayden.reed@starkindustries.ss",
  "kiefer.franks@amazonia.hk",
  "oz.mcguire@tortelloni.zw",
  "ellisandro.noble@bluthhousing.party",
  "alyas.briggs@taitos.ninja",
  "windsor.raymond@hungryhungyhippopottumoses.co.uk",
  "daniyal.brock@hungryhungyhippopottumoses.ug",
  "samatar.benson@duffbeer.org",
  "jaime.freeman@gringottsbank.li",
  "aaron.pace@starkindustries.org",
  "guerin.mcgowan@taitos.li",
  "believe.cote@virtucon.hk",
  "abdalroof.ray@oscorp.co.uk",
  "blake.barrett@tortelloni.org",
  "bradlie.brooks@dundermifflin.ug",
  "rayyan.garza@tortelloni.ug",
  "declan.wood@dundermifflin.ug",
  "tymon.blackburn@oscorp.com",
  "joash.duffy@wonkaindustries.ug",
  "aleksander.ford@umbrellacorporation.fi",
  "jaida.colon@macrosloft.se",
  "jevan.jensen@lospolloshermanos.zw",
  "abubakar.palmer@dundermifflin.org",
  "cator.joyce@lospolloshermanos.org",
  "valen.henry@gringottsbank.co.uk",
  "taylor-jay.blackburn@wonkaindustries.ug",
  "leonardo.mcfadden@goldenstatuettes.co.uk",
  "noel.schneider@hungryhungyhippopottumoses.co.uk",
  "will.osborne@tasavallanpresidentti.com",
  "arda.aguilar@oscorp.fi",
  "omri.walls@virtucon.ug",
  "lliam.briggs@tortelloni.se",
  "kris.lester@amazonia.fi",
  "skye.soto@wonkaindustries.se",
  "dermot.vang@goldenstatuettes.com",
  "cruiz.simmons@cookykitchens.co.uk",
  "tymoteusz.riley@tortelloni.fi",
  "kaidyn.hays@aperaturescience.party",
  "apisai.fletcher@oscorp.co.uk",
  "kedrick.mcfadden@cookykitchens.com",
  "archibald.elliott@gringottsbank.hk",
  "kjae.hurley@umbrellacorporation.com",
  "tymon.nielsen@hungryhungyhippopottumoses.fi",
  "james.dejesus@amazonia.party",
  "reno.silva@gringottsbank.ug",
  "tayyib.brooks@taitos.ss",
  "cormack.alexander@duffbeer.ss",
  "obieluem.guerra@umbrellacorporation.party",
  "hector.moran@dundermifflin.co.uk",
  "logan.parrish@wonkaindustries.com",
  "robin.rivers@starkindustries.zw",
  "albie.spence@tasavallanpresidentti.hk",
  "qasim.schwartz@duffbeer.zw",
  "aodhan.cooper@tasavallanpresidentti.org",
  "eassan.hobbs@lospolloshermanos.org",
  "parkash.juarez@wonkaindustries.party",
  "teos.horton@haxhoont.se",
  "kuba.larsen@duffbeer.ninja",
  "eisa.beard@umbrellacorporation.li",
  "hamza.french@starkindustries.org",
  "sung.randall@taitos.ss",
  "samir.bond@virtucon.org",
  "conlyn.mckee@goldenstatuettes.com",
  "thiago.hooper@starkindustries.com",
  "demetrius.holland@macrosloft.zw",
  "uchenna.oneill@hungryhungyhippopottumoses.zw",
  "windsor.steele@hungryhungyhippopottumoses.fi",
  "keiryn.macias@tasavallanpresidentti.org",
  "kehinde.allen@cookykitchens.hk",
  "yuri.ramirez@macrosloft.zw",
  "ruan.perez@umbrellacorporation.org",
  "dyllon.young@dundermifflin.zw",
  "lockey.mcmahon@goldenstatuettes.fi",
  "lyndsay.haynes@goldenstatuettes.ninja",
  "dareh.grimes@macrosloft.co.uk",
  "veeran.vinson@cookykitchens.fi",
  "jayke.schroeder@lospolloshermanos.org",
  "aronas.berry@bluthhousing.li",
  "jonothan.donaldson@gringottsbank.zw",
  "kenzeigh.weber@umbrellacorporation.se",
  "cesare.huber@tasavallanpresidentti.com",
  "uzair.harris@virtucon.ninja",
  "kelan.yates@taitos.co.uk",
  "thomson.gonzales@bluthhousing.co.uk",
  "keaton.green@umbrellacorporation.hk",
  "jazeb.kinney@duffbeer.co.uk",
  "ronald.flores@starkindustries.hk",
  "alastair.moses@umbrellacorporation.se",
  "ogheneochuko.ratliff@aperaturescience.se",
  "kenton.conley@gringottsbank.ninja",
  "kashif.trujillo@bluthhousing.hk",
  "saghun.ayers@taitos.hk",
  "kamil.eaton@lospolloshermanos.org",
  "bailee.henson@goldenstatuettes.li",
  "alexei.stanton@haxhoont.li",
  "basher.clarke@taitos.li",
]



const Names = (emails) => {
  emails.map(i => {
    console.log("firstname", i.substring(0, i.indexOf(".")));
    console.log("fullname", i.substring(0, i.lastIndexOf("@")));
    console.log("lastname");
  })
};

Names(emails)

Advertisement

Answer

use replace to remove ‘.’.

lastname can be get in substring between ‘.’ and ‘@’

const emails = [
  "peter.pittman@taitos.com",
  "ayden.reed@starkindustries.ss",
  "kiefer.franks@amazonia.hk",
  "oz.mcguire@tortelloni.zw",
  "ellisandro.noble@bluthhousing.party",
  "alyas.briggs@taitos.ninja",
  "windsor.raymond@hungryhungyhippopottumoses.co.uk",
  "daniyal.brock@hungryhungyhippopottumoses.ug",
  "samatar.benson@duffbeer.org",
  "jaime.freeman@gringottsbank.li",
  "aaron.pace@starkindustries.org",
  "guerin.mcgowan@taitos.li",
  "believe.cote@virtucon.hk",
  "abdalroof.ray@oscorp.co.uk",
  "blake.barrett@tortelloni.org",
  "bradlie.brooks@dundermifflin.ug",
  "rayyan.garza@tortelloni.ug",
  "declan.wood@dundermifflin.ug",
  "tymon.blackburn@oscorp.com",
  "joash.duffy@wonkaindustries.ug",
  "aleksander.ford@umbrellacorporation.fi",
  "jaida.colon@macrosloft.se",
  "jevan.jensen@lospolloshermanos.zw",
  "abubakar.palmer@dundermifflin.org",
  "cator.joyce@lospolloshermanos.org",
  "valen.henry@gringottsbank.co.uk",
  "taylor-jay.blackburn@wonkaindustries.ug",
  "leonardo.mcfadden@goldenstatuettes.co.uk",
  "noel.schneider@hungryhungyhippopottumoses.co.uk",
  "will.osborne@tasavallanpresidentti.com",
  "arda.aguilar@oscorp.fi",
  "omri.walls@virtucon.ug",
  "lliam.briggs@tortelloni.se",
  "kris.lester@amazonia.fi",
  "skye.soto@wonkaindustries.se",
  "dermot.vang@goldenstatuettes.com",
  "cruiz.simmons@cookykitchens.co.uk",
  "tymoteusz.riley@tortelloni.fi",
  "kaidyn.hays@aperaturescience.party",
  "apisai.fletcher@oscorp.co.uk",
  "kedrick.mcfadden@cookykitchens.com",
  "archibald.elliott@gringottsbank.hk",
  "kjae.hurley@umbrellacorporation.com",
  "tymon.nielsen@hungryhungyhippopottumoses.fi",
  "james.dejesus@amazonia.party",
  "reno.silva@gringottsbank.ug",
  "tayyib.brooks@taitos.ss",
  "cormack.alexander@duffbeer.ss",
  "obieluem.guerra@umbrellacorporation.party",
  "hector.moran@dundermifflin.co.uk",
  "logan.parrish@wonkaindustries.com",
  "robin.rivers@starkindustries.zw",
  "albie.spence@tasavallanpresidentti.hk",
  "qasim.schwartz@duffbeer.zw",
  "aodhan.cooper@tasavallanpresidentti.org",
  "eassan.hobbs@lospolloshermanos.org",
  "parkash.juarez@wonkaindustries.party",
  "teos.horton@haxhoont.se",
  "kuba.larsen@duffbeer.ninja",
  "eisa.beard@umbrellacorporation.li",
  "hamza.french@starkindustries.org",
  "sung.randall@taitos.ss",
  "samir.bond@virtucon.org",
  "conlyn.mckee@goldenstatuettes.com",
  "thiago.hooper@starkindustries.com",
  "demetrius.holland@macrosloft.zw",
  "uchenna.oneill@hungryhungyhippopottumoses.zw",
  "windsor.steele@hungryhungyhippopottumoses.fi",
  "keiryn.macias@tasavallanpresidentti.org",
  "kehinde.allen@cookykitchens.hk",
  "yuri.ramirez@macrosloft.zw",
  "ruan.perez@umbrellacorporation.org",
  "dyllon.young@dundermifflin.zw",
  "lockey.mcmahon@goldenstatuettes.fi",
  "lyndsay.haynes@goldenstatuettes.ninja",
  "dareh.grimes@macrosloft.co.uk",
  "veeran.vinson@cookykitchens.fi",
  "jayke.schroeder@lospolloshermanos.org",
  "aronas.berry@bluthhousing.li",
  "jonothan.donaldson@gringottsbank.zw",
  "kenzeigh.weber@umbrellacorporation.se",
  "cesare.huber@tasavallanpresidentti.com",
  "uzair.harris@virtucon.ninja",
  "kelan.yates@taitos.co.uk",
  "thomson.gonzales@bluthhousing.co.uk",
  "keaton.green@umbrellacorporation.hk",
  "jazeb.kinney@duffbeer.co.uk",
  "ronald.flores@starkindustries.hk",
  "alastair.moses@umbrellacorporation.se",
  "ogheneochuko.ratliff@aperaturescience.se",
  "kenton.conley@gringottsbank.ninja",
  "kashif.trujillo@bluthhousing.hk",
  "saghun.ayers@taitos.hk",
  "kamil.eaton@lospolloshermanos.org",
  "bailee.henson@goldenstatuettes.li",
  "alexei.stanton@haxhoont.li",
  "basher.clarke@taitos.li",
]



const Names = (emails) => {
  emails.map(i => {
    console.log("firstname:", i.substring(0, i.indexOf(".")),
                ", fullname:", i.substring(0, i.lastIndexOf("@")).replace(".", ""),
                ", lastname:", i.substring(i.indexOf(".")+1, i.lastIndexOf("@")));
  })
};

Names(emails)
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement