Email duplication check from array

Clash Royale CLAN TAG#URR8PPP
Email duplication check from array
I have two emails and I'm trying to check if it matches anything in my data array which is a an array of emails.
I thought the below would return true or false but it seems to be not working.
const email1 = test.emailAddress.value;
const email2 = test2.emailAddress.value;
data.every(( email ) => email.value === email1 || email.value === email2);
some()
You want to check if every item in the array matches
email1 or email2?– vlaz
13 mins ago
email1
email2
Whats the structure of
data?– Abdulfatai
13 mins ago
data
3 Answers
3
You can filter your data with the matched array of two emails like so:
filter
const data = [
email: 'test@test.com',
email: 'test1@test.com',
email: 'test2@test.com'
]
const email1 = 'test1@test.com'
const email2 = 'test2@test.com'
const matched = data.filter(( email ) => [email1, email2].includes(email));
console.log(matched)
According to your code, the .every method checks if every email in the data array is either email1 or email2, if at least one of the emails in the data array fails the condition, the .every method returns false. Which means that the .every method is not suitable for what you want to achieve.
.every
email
data
email1
email2
data
.every
.every
var exists = data.filter((email) => [email1, email2].includes(email)).length > 0
Unless you provide your data it is hard to figure out what is going on. But you can useincludes to check if an element is present in an array or not.
data
includes
The includes() method determines whether an array includes a certain element, returning true or false as appropriate.
if( data.includes(email1) || data.includes(email2))
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
sounds like you need to use Array.some; The
some()method tests whether at least one element in the array passes the test implemented by the provided function– Sphinx
14 mins ago