“Javascript termasuk” Kode Jawaban

JavaScript string berisi

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

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

Array JavaScript berisi

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

JavaScript berisi 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

Daftar JavaScript termasuk

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 termasuk

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

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

Javascript termasuk

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

Jawaban yang mirip dengan “Javascript termasuk”

Pertanyaan yang mirip dengan “Javascript termasuk”

Lebih banyak jawaban terkait untuk “Javascript termasuk” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya