Why includes() works with a string?


In MDN doc : " The includes() method determines whether an array includes a certain value among its entries, returning true or false as appropriate."

But If I use a string:

let string = 'string'

That’s works well.
Why ?

includes is also defined on the string prototype:

There are a fair number of methods that work on both strings and arrays. When I’m in doubt, I just Google “MDN methodname” and if its defined for both arrays and strings those two pieces of documentation are typically the first two results.

Yes, good trick ! :wink:
Thanks again as usually.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.