array1 = [{id: 1, email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="92e6f7e1e6a3d2e6f7e1e6bcf1fdff">[email protected]</a>', group_ids: ["25"], username: 'test1'},
{id: 2, email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c4b0a1b7b0f684b0a1b7b0eaa7aba9">[email protected]</a>', group_ids: ["22"], username: 'test2'},
{id: 3, email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0f7b6a7c7b3c4f7b6a7c7b216c6062">[email protected]</a>', group_ids: ["25", "20"], username: 'test3'},
{id: 4, email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="32465741460672465741461c515d5f">[email protected]</a>', group_ids: ["23"], username: 'test4'}]
array2 = [25, 22];
I am trying to extract the email addresses from array1 that have group_ids matching those in array2. However, my current method is not giving me the correct result. Any assistance would be greatly appreciated.
var user_groupId = [];
var emails = [];
var obj = [];
for (var i=0; i < array2.length; i++) {
obj.push(array1.find(o => o.group_ids.find( b => b == array2[i])));
}
for (var i=0; i< obj.length; i++){
emails.push(obj[i].email);
}
console.log(emails);
As of now, the output Array is ["[email protected]", "[email protected]"], however, it is missing "[email protected]". Thank you for your help.