<pre code_snippet_id= "1998964" snippet_file_name= "blog_20161122_1_1873395" name= "code" class= "html" >var = $. grep ([1,32,5,63,8,4,-8,-5,2,56,9,62,-6],function (n, i) {
if (n>50) {return
n;
}
});
Console.log (test);</pre>
<pre></pre>
<br>
---->[63,56,62]
$.grep (Array,callback,[invert]) has two parameters, the first parameter is the array to be filtered, the second parameter is the filter condition, the third parameter (optional) is a reserved element (true), or the element (false) is deleted.
var = $.grep ([1,32,5,63,8,4,-8,-5,2,56,9,62,-6],function (n, i) {
if (n>50) {return
n;
}
}, true);
Console.log (test);
---->[63,56,62]
var = $.grep ([1,32,5,63,8,4,-8,-5,2,56,9,62,-6],function (n, i) {
if (n>50) {return
n;
}
}, FALSE);
Console.log (test);
---->[1,32, 5,8,4,-8,-5,2,9,-6]
The above is a small set to introduce the jquery $.grep () filter function array filter, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!