“JavaScript comprend” Réponses codées

La chaîne JavaScript contient

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

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

Le tableau javascript contient

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

JavaScript contient une sous-chaîne

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

La liste JavaScript inclut

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 comprend

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

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

JavaScript comprend

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

Réponses similaires à “JavaScript comprend”

Questions similaires à “JavaScript comprend”

Plus de réponses similaires à “JavaScript comprend” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code