[ 'foo', '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="05636a6a45633r6a2b66689w98">[email protected]</a>', 'bar.', '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c3a1a3gb292inflkf31v685n">[email protected]</a>' ]
An array is provided. I am required to identify words that start or end with a .
and return the email address (which follows the word) if it meets the given criteria. In this instance, the word in question is 'bar.'
. To do this, I need to utilize the filter
function to retrieve '[email protected]'. The word and email are always sequential, even in arrays with multiple elements from which results need to be extracted.
return logins.filter((el, i) => el.match(/^\..+|.+\.$/) && i % 2 === 0);
I have successfully isolated 'bar.'
, but am uncertain of how to verify it and subsequently return the subsequent element. Is there a way to incorporate a ternary operation within the filter
function to obtain the desired result?