var nickNames = [
{
nickName:"Father",
emailAddress:"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ec888d88ac888d88c28f8381">[email protected]</a>",
},
{
nickName:"Mother",
emailAddress:"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ff929092bf929092d19c9092">[email protected]</a>",
},
{
nickName:"Bestie",
emailAddress:"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="77151111371511115914181a">[email protected]</a>",
}
]
var emails = [
{
from:"Dad Dadson <<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="30545154705451541e535f5d">[email protected]</a>>"
},
{
from:"Mom Dadson <<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7815171538151715561b1715">[email protected]</a>>"
},
{
from:"Brother Dadson <<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="98faeaf7d8faeaf7b6fbf7f5">[email protected]</a>>"
}
]
for (var i=0; i < emails.length; i++) {
emails[i].from.replace(/ *\<[^)]*\> */g, "")
}
for (var i=0; i < emails.length; i++) {
if (emails.find(email => email.from) === nickNames.find(nick => nick.emailAddress)) {
emails[i].nickName = nick.nickName
}
}
Attempting to achieve two goals:
- Check both arrays for any matches between:
nickNames.emailAddress
and
emails.from
The regular expression used to extract the email address works in a different part of my code, but not here.
- If there is a match, add a new key-value pair in the matching email array element, with the corresponding nickname.
Expected outcome:
emails = [
{
from:"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="294d484d694d484d074a4644">[email protected]</a>",
nickName: "Father"
},
{
from:"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="573a383a173a383a7934383a">[email protected]</a>",
nickName: "Mother"
},
{
from:"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6a0818052a08180544090507">[email protected]</a>"
}
]
Appreciate any help you can offer!