“Temukan String di Array JavaScript” Kode Jawaban

Pencarian JavaScript di array string

var arr = ['hello my name is harendra','hello my name is gyanendra']
result = arr.filter(element => element.includes("harendra"));
console.log(result)
Harendra

Temukan String di Array JavaScript

var myarr = ["I", "like", "turtles"];
var arraycontainsturtles = (myarr.indexOf("turtles") > -1);
Dr.Paashaas

Cari di String Array JavaScript

function searchStringInArray (str, strArray) {
    for (var j=0; j<strArray.length; j++) {
        if (strArray[j].match(str)) return j;
    }
    return -1;
}
JulesG10

Elemen JavaScript di Array

var fruits = ["Banana", "Orange", "Apple", "Mango"];

var n = fruits.includes("Mango");
Brave Bear

Periksa apakah array tidak berisi string js

function checkInput(input, words) {
 return words.some(word => input.toLowerCase().includes(word.toLowerCase()));
}

console.log(checkInput('"Definitely," he said in a matter-of-fact tone.', 
["matter", "definitely"]));
Vu Nguyen

Periksa apakah array tidak berisi string js

function checkInput(input, words) {
 return words.some(word => new RegExp(word, "i").test(input));
}

console.log(checkInput('"Definitely," he said in a matter-of-fact tone.', 
["matter", "definitely"]));
Vu Nguyen

Jawaban yang mirip dengan “Temukan String di Array JavaScript”

Pertanyaan yang mirip dengan “Temukan String di Array JavaScript”

Lebih banyak jawaban terkait untuk “Temukan String di Array JavaScript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya