/* Filter () each element in the array executes a specified function (callback), and a new array is created, which is the original array element whose return value is true when all callback functions are executed.
It executes the specified function only for non-null elements in the array, the elements that are not assigned or have been deleted are ignored, and the newly created array does not contain those elements.
The callback function can have three parameters: the current element, the index of the current element, and the current array object. *///raw data var arrs = [{name: "Tom", Age:18, Sex: "Boy"}, {name: "Jim", Age:19, Sex:
"Boy"}, {name: "anchor", Age:20, Sex: "Boy"}, {name: "Lucy", Age:18, Sex: "Girl"
}, {name: "Lily", age:19, Sex: "Girl"}, {name: "Andy", Age:20, Sex: "Girl"}];
Filter condition var limits = {name: ' Tom ', age:18, Sex: ' Boy '};
Filter callback functions function Dofilter (element, index, array) {if (limits.name && limits.name!= element.name) {//Name filter
return false;
}else if (limits.age && limits.age!= element.age) {//Age filter return false;
}else if (limits.sex && limits.sex!= element.sex) {//sex filter return false;
return true;
/* Test */var filtered = Arrs.filter (dofilter); ConsoLe.log (filtered);