“JavaScript enthält” Code-Antworten

JavaScript String enthält

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

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

JavaScript Array enthält

var colors = ["red", "blue", "green"];
var hasRed = colors.includes("red"); //true
var hasYellow = colors.includes("yellow"); //false
Grepper

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

Die JavaScript -Liste umfasst

const array1 = [1, 2, 3];

console.log(array1.includes(2));
// expected output: true

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

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

console.log(pets.includes('at'));
// expected output: false
Determined Deer

JavaScript enthält

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

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

JavaScript enthält

includes(searchElement)
includes(searchElement, fromIndex)
Fierce Fish

Ähnliche Antworten wie “JavaScript enthält”

Fragen ähnlich wie “JavaScript enthält”

Weitere verwandte Antworten zu “JavaScript enthält” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen