请查看以下代码:
var textArray = new Array();
var allText = results.data._contained.text;
for (var i = 0; i < allText.length; i++) {
var text1 = allText[i];
var textHtml = "<div id='text_item'>";
textHtml += "<span class='some_div'>{0}</span>".replace("{0}", text1.text_is);
textHtml += "</div>";
textArray.push(text1.texts.priority);
$("#text_box").append(textHtml);
}
if (foo === 'Some text') {
document.write("match");
} else {
document.write("not match");
}
}
在上面的代码中,我在数组中获取值。然后在下面我有这个if / else语句。如何从阵列中一次抓取一个值并与#34;某些文本进行比较&#34;?
答案 0 :(得分:1)
for (var i = 0; i < allText.length; i++) {
var text1 = allText[i];
if (text1 === 'Some text') {
document.write("match");
}
else {
document.write("not match");
}
....
}