How to check whether a string contains a substring in JavaScript?
var str = "Hello world, welcome to the universe.";
var n = str.includes("world");var str = "We got a poop cleanup on isle 4.";
if(str.indexOf("poop") !== -1){
alert("Not again");
}
//use indexOf (it returns position of substring or -1 if not found)var str = "We got a poop cleanup on isle 4.";
if(str.indexOf("poop") !== -1){
alert("Not again");
}
Also in JavaScript:
- javascript append to array
- javascript random color generator
- jquery $(document.on click
- how to add json data to xmlhttprequest
- javascript remove all newlines
- scalar
- db.json
- jquery scrollHeight
- open pdf in new tab javascript
- insert json into sql
- js number padding to number of characters
- strapi cloudinary how to use
- cypress memory leak
- js detect mouse support
- javascript add class
- javascript objet keys comparaison
- js find space in string
- How to make PWAs installable js
- javascript vérifier si une chaine de carctère commence par une majuscule
- get file extension of path extendscript
- new jsonobject java
- mongoose reference another model
- javascript check image src
- eslint ignore current line