How to check whether a string contains a substring in JavaScript?

Опубликовано: 28 Сентябрь 2024
на канале: Code Samples
69
2

#javascript
#string
#substring
Usually I would expect a String.contains() method, but there doesn't seem to be one.
What is a reasonable way to check for this?
String.prototype.includes: https://developer.mozilla.org/en-US/d...
is not supported by Internet Explorer: https://caniuse.com/#closures polyfill: https://github.com/zloirock/core-js/b...
String.prototype.indexOf: https://developer.mozilla.org/en-US/d...