0

I am trying to find in an array includes SOME of the text in an element. Here is what I have:

['red', 'green', 'blue'].some(e => e.includes('red:square')) // false

Which returns false. But I would like it to return true because obviously red is inside one of the elements of the array.

2 Answers 2

3

You can use Alternation ( | ) and Search function

console.log(['red', 'green', 'blue'].some(e => e.search(/red|square/)))

Sign up to request clarification or add additional context in comments.

Comments

1

 console.log(['red', 'green', 'blue'].some(e => ['red','square'].includes(e))) //positive test case 


 console.log(['red', 'green', 'blue'].some(e => ['white','square'].includes(e))) //negative test case 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.