“Enthält in JavaScript” Code-Antworten

JavaScript String enthält

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

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

JavaScript 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

JavaScript enthält

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

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

.Includes Bedeutung in JavaScript

let fruits = ['mango', 'banana', 'pineapple', 'tomato'];

console.log(fruits.includes('banana')); //Returns True because banana is included it the list
console.log(fruits.includes('orange')); // Returns False, orange is not in the list
Gleaming Goosander

Enthält in JavaScript

const friendsList = ["Abir", "Lalkhan", "Lion", "Shamol", "Kabir", "Shabir"];
if (friendsList.includes("Lion") == true) {
    console.log("Lion is Exists");
}
//Output: Lion is Exists
Ariful Islam Adil(Code Lover)

Enthält in JavaScript

'a nice string'.includes('a') //true
'a nice string'.includes('b') //false
Fair Flamingo

Ähnliche Antworten wie “Enthält in JavaScript”

Fragen ähnlich wie “Enthält in JavaScript”

Weitere verwandte Antworten zu “Enthält in JavaScript” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen