“JavaScript inclui” Respostas de código

String javascript contém

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

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

JavaScript Array contém

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

JavaScript contém 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

Lista de JavaScript inclui

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 inclui

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

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

JavaScript inclui

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

Respostas semelhantes a “JavaScript inclui”

Perguntas semelhantes a “JavaScript inclui”

Mais respostas relacionadas para “JavaScript inclui” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código