“Die JavaScript -Zeichenfolge enthält Substring” Code-Antworten

Überprüfen Sie, ob String ein Substring in JavaScript enthält?

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

console.log(string.includes(substring));  //true
Batman

Die JavaScript -Zeichenfolge enthält 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)
Grepper

.Includes (String


var str = "Hello world, welcome to the universe.";
var n = str.includes("world");
 
Black Necked Stork

JavaScript enthält

const pets = ['cat', 'dog', 'bat'];

console.log(pets.includes('cat'));
// output: true
Batman

So überprüfen Sie, ob eine Zeichenfolge ein Substring in JavaScript enthält

const string = "foo";
const substring = "oo";

console.log(string.includes(substring)); // true
 Run code snippet
Angry Albatross

String.Containt JavaScript

var str = "We got a poop cleanup on isle 4.";
if(str.indexOf("poop") !== -1){
	alert("Not again");
}
Misty Manatee

Ähnliche Antworten wie “Die JavaScript -Zeichenfolge enthält Substring”

Fragen ähnlich wie “Die JavaScript -Zeichenfolge enthält Substring”

Weitere verwandte Antworten zu “Die JavaScript -Zeichenfolge enthält Substring” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen