Code:
--------------------------------------------------------------------------------
The code is as follows |
Copy Code |
function Isbigenough (element, index, array) { Return (element >= 10); } var filtered = [5, 8, 130, 44].filter (Isbigenough);
|
12, 130, 44
Results:
--------------------------------------------------------------------------------
[5, 8, 130, 44].filter (Isbigenough): 12, 130, 44
Full instance
code is as follows |
copy code |
<script Language= "JavaScript" type= "Text/javascript" if (! Array.prototype.filter) { Array.prototype.filter=function (fun) { var len=this.length; if (typeof fun!= "function") throw new TypeError (); var res=new Array (); var thisp=arguments[1]; for (Var i=0;i< len;i++) {if (i) {var val=this[i];if (Fun.call (thisp,val,i,this)) Res.push (val);}} return res;;} Function Isbigenough (Element,index,array) {return (element>=10);} var filtered=[12,5,8,130,44].filter (Isbigenough); Document.writeln ("[5, 8, 130, 44].filter (Isbigenough):<strong>"); Document.writeln (Filtered.join (",")); Document.writeln ("</strong><br/>"); </script> |