有人能告诉我如何检测数组中是否出现"specialword"
吗?例子:
categories: [
"specialword"
"word1"
"word2"
]
有人能告诉我如何检测数组中是否出现"specialword"
吗?例子:
categories: [
"specialword"
"word1"
"word2"
]
你真的不需要jQuery来实现这个.
var myarr = ["I", "like", "turtles"];
var arraycontainsturtles = (myarr.indexOf("turtles") > -1);
Hint:indexOf返回一个数字,表示指定的搜索值第一次出现的位置,如果从未出现,则返回-1
或
function arrayContains(needle, arrhaystack)
{
return (arrhaystack.indexOf(needle) > -1);
}
It's w或th noting that array.indexOf(..)
is not supp或ted in IE < 9, but jQuery's indexOf(...)
function will w或k even f或 those older versions.