string.includes()
determines if a string can be found inside another one
finding a single character
- can be done (a character is also a string, in JS)
- reports false if character was not found
find a string
- that matches exactly
search for an empty string, is always true
- in an empty string
- in
abc
special/corner cases
- search for
undefined
in a string fails - searches are case-sensitive
- must NOT be a regular expression
coerces the searched "thing" into a string
- e.g. from a number
- e.g. from an array
- e.g. from an object, with a
toString()
method
takes a position from where to start searching
- does not find
a
after position 1 inabc
- even the position gets coerced
invalid positions get converted to 0
- e.g.
undefined
- negative numbers
- NaN
Links
The official specification, actually quite good to read for this function.
The Mozilla Developer Network docs, contains good examples.