Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 数组包含不';捕获_Javascript_Jquery_Arrays - Fatal编程技术网

Javascript 数组包含不';捕获

Javascript 数组包含不';捕获,javascript,jquery,arrays,Javascript,Jquery,Arrays,我有一个数组,数组看起来像这样,我想知道数组中包含的是NewsType=“Int” 数组是NewsTypeArray 当我在firebug.array中调试时,如下所示 0 Object { NewsType="Local"} 1 Object { NewsType="Int"} var InternationalNewsfound = $.inArray("Int", NewsTypeArray) > -1; 但是 InternationalNewsfound显示为false。您

我有一个数组,数组看起来像这样,我想知道数组中包含的是NewsType=“Int”

数组是NewsTypeArray

当我在firebug.array中调试时,如下所示

0 Object { NewsType="Local"}
1 Object { NewsType="Int"}

var InternationalNewsfound  = $.inArray("Int", NewsTypeArray)  > -1;
但是
InternationalNewsfound显示为false。

您正在搜索一个对象数组,但您的搜索值是一个字符串(
“Int”)
<代码>inArray在这里帮不了你

ES5将会(如果您需要支持像IE8这样的过时浏览器,可以使用它):

var NewsTypeArray=[{“NewsType”:“Local”},{“NewsType”:“Int”}];
var InternationalNewsfound=NewsTypeArray.some(函数(e){
返回e.NewsType==“Int”;
});

console.log(InternationalNewsfound)将筛选器与jquery一起使用

var NewsTypeArray=[{“NewsType”:“Local”},{“NewsType”:“Int”}];
var InternationalNewsfound=$.grep(新闻类型数组,函数(obj){
返回obj.NewsType==“Int”;
}).长度>0;
console.log(InternationalNewsfound)

这是因为要将对象与字符串进行比较。请使用
$.grep()
检查对象属性。