我如何才能找到一个关键字是否存在于使用split()分割的数组中?jquery match:如何查找数组中是否存在关键字?
// Get the object infomation.
var keyword = 'story';
var path = $(this).find('a').attr('href');
var array_url = path.split('/');
if(keyword == array_url) alert('match!'); // does it work like this??
从代码的网址路径是这样的 - www.mysite.com/story/article-1
感谢。
编辑:
if ($.inArray(keyword, array_url)) alert('match!');
这将提醒匹配的数组中是否有与否的关键字。
听起来类似于:http://stackoverflow.com/questions/143847/best-way-to-find-an-item-in-a-javascript-array – JMax