Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.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 如何使用jQuery.grep()过滤多维JSON对象_Javascript_Jquery_Json - Fatal编程技术网

Javascript 如何使用jQuery.grep()过滤多维JSON对象

Javascript 如何使用jQuery.grep()过滤多维JSON对象,javascript,jquery,json,Javascript,Jquery,Json,我有一个JSON对象,如下所示: {"data": [ {"name":"Alan","height":"171","weight":"66"}, {"name":"Ben","height":"182","weight":"90"}, {"name":"Chris","height":"163","weight":"71"} ] ,"school":"Dover Secondary" } 我想过滤JSON对象,以获得高于170和高于70的数据,然后对该对象进行排序。从中,我

我有一个JSON对象,如下所示:

{"data":
 [
  {"name":"Alan","height":"171","weight":"66"},
  {"name":"Ben","height":"182","weight":"90"},
  {"name":"Chris","height":"163","weight":"71"}
 ]
 ,"school":"Dover Secondary"
}
我想过滤JSON对象,以获得高于170和高于70的数据,然后对该对象进行排序。从中,我了解到在线性阵列上很容易实现滤波,如下所示:

arr = jQuery.grep(arr, function(element, index){
  return (element > 70 && index = 'weight');
});
如何同时过滤体重和身高以获得以下信息:

{"data":
 [
  {"name":"Ben","height":"182","weight":"90"},
 ]
 ,"school":"Dover Secondary"
}
我想你的意思是:


那不是我真正的体重和身高!犯错误我想过滤体重和身高。能做到吗?
var obj = {"data":
 [
  {"name":"Alan","height":"171","weight":"66"},
  {"name":"Ben","height":"182","weight":"90"},
  {"name":"Chris","height":"163","weight":"71"}
 ]
 ,"school":"Dover Secondary"
};

obj.data = jQuery.grep(obj.data, function(element, index){
  return element.weight > 70 && element.height > 170; // retain appropriate elements
});