Filtering works fine for an object (data) wrapping around an array of objects:
var arr = {"data":
[
{"name":"Alan","height":"171","weight":"66"},
{"name":"Ben","height":"182","weight":"90"},
{"name":"Chris","height":"163","weight":"71"}
]
};
var new_arr = $.extend(true, arr);
new_arr.data = $.grep(new_arr.data, function(n, i){
return n.weight > 70;
});
alert(new_arr.data.length); // answer is 2
However, filtering without the object wrapper doesn't.
var arr = [
{"name":"Alan","height":"171","weight":"66"},
{"name":"Ben","height":"182","weight":"90"},
{"name":"Chris","height":"163","weight":"71"}
];
var new_arr = $.extend(true, arr);
new_arr = $.grep(new_arr, function(n, i){
return n.weight > 70;
});
alert(new_arr.length); // answer is 1 instead of 2
I am not sure where is the problem. Can anyone point out. Thanks!