ECMAScript 6 introduced String.prototype.includes
:
const string = "foo"; const substring = "oo"; console.log(string.includes(substring)); // true
includes
doesn’t have Internet Explorer support, though. In ECMAScript 5 or older environments, use String.prototype.indexOf
, which returns -1 when a substring cannot be found:
var string = "foo"; var substring = "oo"; console.log(string.indexOf(substring) !== -1); // true
Related Posts:
- How do I check if string contains substring? [duplicate]
- How do I check if string contains substring?
- Check if a string has a certain piece of text [duplicate]
- How to convert a string to an integer in JavaScript?
- How can I do string interpolation in JavaScript?
- How do I make the first letter of a string uppercase in JavaScript?
- How do I make the first letter of a string uppercase in JavaScript?
- Creating multiline strings in JavaScript
- How do I check if a string contains a specific word?
- Creating multiline strings in JavaScript
- Split string into array
- How do you reverse a string in-place in JavaScript?
- What is the correct way to check for string equality in JavaScript?
- How do I check if a string contains a specific word?
- Check if a variable is a string in JavaScript
- What’s the best way to convert a number to a string in JavaScript?
- Check if a variable is a string in JavaScript
- How can I remove a character from a string using JavaScript?
- How to print elements from array with javascript
- How to remove text from a string?
- What does ${} (dollar sign and curly braces) mean in a string in Javascript?
- Delete first character of a string in Javascript
- ES6: Create Strings using Template Literals – Freecodecamp
- How can I get the last character in a string?
- How can I get the last character in a string?
- Count the number of occurrences of a character in a string in Javascript
- Converting an object to a string
- Anagrams finder in javascript
- How to interpolate variables in strings in JavaScript, without concatenation?
- How can I extract a number from a string in JavaScript?
- String.Format not work in TypeScript
- How to do case insensitive string comparison?
- What is the difference between String.slice and String.substring?
- Uncaught TypeError: Cannot read property ‘toUpperCase’ of undefined
- How to remove part of a string?
- Escaping HTML strings with jQuery
- Replace all spaces in a string with ‘+’
- How to count string occurrence in string?
- Insert a string at a specific index
- Strip HTML from Text JavaScript
- Strip all non-numeric characters from string in JavaScript
- Wildcard string comparison in Javascript
- Replace spaces with dashes and make all letters lower-case
- Check if a JavaScript string is a URL
- Maximum call stack size exceeded error
- What is VanillaJS?
- What’s the difference between using “let” and “var”?
- Optimum way to compare strings in JavaScript?
- JavaScript getElementByName doesn’t work
- jQuery.click() vs onClick
- Understanding nested for loops in javascript
- await is only valid in async function
- Tricky : ‘dict’ object is not callable
- Scroll to an element with jQuery
- Download File Using JavaScript/jQuery
- How to create a stopwatch using JavaScript?
- Use of $parse in angular js
- Find the largest palindrome made from the product of two 3-digit numbers – Javascript
- Javascript/Jquery Convert string to array
- Difference between “module.exports” and “exports” in the CommonJs Module System
- Local package.json exists, but node_modules missing
- How to add a keyboard listener to my onClick handler?
- GulpUglifyError:Unable to minify JavaScript
- why angularjs ng-repeat not working
- jQuery remove options from select
- Convert UTC Epoch to local date
- Bootstrap modal – close modal when “call to action” button is clicked
- Javascript: difference between a statement and an expression?
- Keep getting a “Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup” when attempting to google plus login on my web app
- The entity name must immediately follow the ‘&’ in the entity reference
- How can I use goto in Javascript?
- Javascript Function that returns true if a letter?
- How do I know which version of Javascript I’m using?
- getContext is not a function
- lodash multi-column sortBy
- Calling a JavaScript function in another js file
- JavaScript code not running in HTML5 document
- What is the cause for “angular is not defined”
- How to use wp_localize_script in custom page template?
- Force core to use .dev JavaScript files
- TinyMCE Button to Insert Multiple Lines of Text?
- How to add extra attributes to the script tag added via wp_localize_script()
- How to get value of selected page template in Gutenberg editor?
- How to place script in footer?
- AngularJS with route and JSON API
- List of JS Events for Widgets?
- Authentication with the Rest API when using an External Application
- Open Featured Image Modal in WordPress Gutenberg onClick of a button
- in jquery read a multidimensional array via wp_localize_script()
- Uncaught ReferenceError: jQuery is not defined – although jQuery is loaded [closed]
- How can I import one custom block into another?
- Custom JS on a specific page
- How to import a JavaScript Library into WordPress
- How to change the link address from internal to external
- Uncaught TypeError: Cannot read property ‘add’ of undefined bp-plupload.min.js
- Where is the Javascript attribute window._wpCustomHeaderSettings defined?
- how to include js in widget?
- JS files landing on page but not working, using childtheme of twentyeleven
- List unused javascript for easy removal
- How to load JavaScript modules with script_loader_tag hook?