Answers for "how to see if a string contains a string in javascript"

1

how to check if a string is in a string js

// Example 1:
const string = "Hello world!";

n = string.includes("world");

// n is equal to true in Example 1

// Example 2:
const string = "Hello world!, I am Kavyansh";

n = string.includes("I am Aman");
// n is equal to false in Example 2
// Note: the .includes method is case sensitive
Posted by: Guest on November-28-2021
38

check if string contains character javascript

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

Code answers related to "how to see if a string contains a string in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language