জাভাস্ক্রিপ্ট অ্যারে ফিল্টার() পদ্ধতি প্রদত্ত ফাংশন দ্বারা বাস্তবায়িত পরীক্ষায় উত্তীর্ণ সমস্ত উপাদান সহ একটি নতুন অ্যারে তৈরি করে৷
নিম্নলিখিত পরামিতিগুলি −
-
কলব্যাক − অ্যারের প্রতিটি উপাদান পরীক্ষা করার ফাংশন।
-
এই বস্তু - কলব্যাক চালানোর সময় এটি ব্যবহার করার জন্য অবজেক্ট।
জাভাস্ক্রিপ্ট -
-এ ফিল্টার() পদ্ধতির সাথে কীভাবে কাজ করবেন তা শিখতে আপনি নিম্নলিখিত কোডটি চালানোর চেষ্টা করতে পারেনউদাহরণ
<html>
<head>
<title>JavaScript Array filter Method</title>
</head>
<body>
<script>
if (!Array.prototype.filter) {
Array.prototype.filter = function(fun /*, thisp*/) {
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 in this) {
var val = this[i]; // in case fun mutates this
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.write("Filtered Value : " + filtered );
</script>
</body>
</html>