PUREJAVASCRIPTを使用して配列内の一致を確認しようとしています。これを行う方法がわかりません。ご協力いただければ幸いです。
var sites = new Array ("site1.com", "site2.com", "site3.com" ...);
// Sites array contains 100 values
var imgs = document.getElementsByTagName("img");
for (var i = 0; i < imgs.length; i++) {
img = imgs[i].src;
// I'm trying to check if is in array,
// and don't waste a lot of size in code
if(img.match(sites)){
notHere(imgs[i]);
}
// This is the working way.
// Even if location is a.site1.com/b/, it will match
if (img.match("site1.com")) {
heReload(imgs[i]);
}
// Repeat this piece of code 100 times
}
}
注:正確な値を確認したくありません。関数をシミュレートしたいmatch()
ので、img = "http:// abc / d /"で、配列が "bc /"の場合、実行されfunction()
ます。