I am trying to find if second array has any string from the first one. Not sure what I am doing wrong
const domainAlertList = ["@domain1", "@tomato2", "@carrot3"];
const search = ["test@domain1.com", "test@tomato2.com"];
const myFunc = () => {
return search.some((r) => domainAlertList.includes(r));
};
console.log(myFunc());
It returns false instead of true
const domainAlertList = ["@domain1", "@tomato2", "@carrot3"];
const search = ["test@domain1.com", "test@tomato2.com"];
const myFunc = () => {
return domainAlertList.some((r) => {
return search.some(t => t.includes(r))
});
};
console.log(myFunc());
You have to map through the second array too like this
const domainAlertList = ["@domain1", "@tomato2", "@carrot3"];
const search = ["test@domain1.com", "test@tomato2.com"];
const myFunc = () => {
return search.some((r) => domainAlertList.some(domain=>{domain.includes(r)});
};
console.log(myFunc());