“Enthält Substring -JavaScript” 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

JavaScript String enthält

var string = "foo",
    substring = "oo";

console.log(string.includes(substring));
Cautious Crane

Enthält Substring -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)
Grepper

JavaScript enthält

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

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

JS überprüfen, ob die Zeichenfolge Zeichen enthält

"FooBar".includes("oo"); // true

"FooBar".includes("foo"); // false

"FooBar".includes("oo", 2); // false
Fragile Fish

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

Ähnliche Antworten wie “Enthält Substring -JavaScript”

Fragen ähnlich wie “Enthält Substring -JavaScript”

Weitere verwandte Antworten zu “Enthält Substring -JavaScript” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen