Answers for "check whether a string contains a substring js"

30

check for substring javascript

const string = "javascript";
const substring = "script";

console.log(string.includes(substring));  //true
Posted by: Guest on July-06-2020
38

javascript contains substring

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)
Posted by: Guest on July-18-2019
0

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

There is a String.prototype.includes in ES6:

"potato".includes("to")
Posted by: Guest on March-15-2022

Code answers related to "check whether a string contains a substring js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language