Using JavaScript I am pulling names out of webpage and stringing them together somehow (probably going with an array). Once I gather all the names together I need to make another string that gives all the email addresses of the names. The email addresses are not on the webpage so I will have to list every possible thisName=thisEmail in my script somehow. I was about to approach this with making a bazillion if statements but I thought there has to be a more efficient way. Any suggestions?
var x = getElementById("names");
var name = x.InnerHTML;
var email;
if (name == 'Steve'){ email == 'steve462@gmail.com'; }
if (name == 'Bob'){ email == 'duckhunter89@gmail.com'; }
....
A switch statement, as your code is only if-elses 🙂
No, honestly. The best thing would be if you’d find a simple algorithm to create an email address from any given name, like
If they differ to much, you might use an object as a key-value-map:
You could also combine those, if you have to determine which algorithm you need to use:
or when it is a bit simpler:
Just try to reduce the amount of data to deliver to the client as much as you can.