【发布时间】:2014-09-04 19:13:07
【问题描述】:
我需要帮助来确定一个数组是否包含两个特定字符串以外的字符串。例如,如果一个字符串有“a”以外的任何内容,它应该会失败。区分大小写并不重要。
var array = ["a", "a", "a", "b"]; // this should fail
var array2 = ["a", "a", "a", "a"]; // this should pass
我在想这样的事情:
var abFound = false;
// Run a for loop and look for the contents of the array element (indexOf) to see if it equals "a" or "b", if it does set abFound to true.
有什么建议或更好的方法吗?
谢谢。
【问题讨论】:
-
循环遍历数组,当你看到除
"a"return false以外的任何东西的那一刻?听起来并不复杂。 -
这是你的课堂作业吗?
标签: javascript arrays search