Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Array.includes not working as string.includes

I want something like string.includes it can detect character among string but array.includes("a") can only detect if array[0] = "a" and return false when array[0] = "ab"

Is there anyway i can achieve string.includes in array without function and loop (1 line code) ? Thanks

var array = ["a", "b"];
array.includes("a"); //return true
var array = ["ab","b"];
array.includes("a"); //return false
Var string = "ab";
string.includes("a"); //return true

I want string.includes working with array without function and loop

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Note that the join variant below will cause problems if the string match itself contains a comma.

const array = ['ab', 'cd']

console.log(array.some(i=>i.includes('a')))

// or

console.log(array.join().includes('a'))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading