জাভাস্ক্রিপ্টের findIndex() পদ্ধতিটি একটি অ্যারের প্রথম উপাদানের সূচী ফেরত দিতে ব্যবহৃত হয়, যদি শর্তটি পাস হয়।
সিনট্যাক্স নিম্নরূপ -
array.findIndex(function(currentValue, index, arr), thisValue)
এখন জাভাস্ক্রিপ্ট -
-এ findIndex() পদ্ধতি প্রয়োগ করা যাকউদাহরণ
<!DOCTYPE html>
<html>
<body>
<h2>Rank</h2>
<button onclick="display()">Result</button>
<p id="demo"></p>
<p>Finding the index of the player with highest rank.</p>
<script>
var points = [100, 150, 200, 250, 300, 400];
function topRank(points) {
return points >= 400;
}
function display() {
document.getElementById("demo").innerHTML = "index = "+points.findIndex(topRank);
}
</script>
</body>
আউটপুট

সূচক পেতে "ফলাফল" এ ক্লিক করুন -

উদাহরণ
<!DOCTYPE html>
<html>
<body>
<h2>Rank</h2>
<button onclick="display()">Result</button>
<p id="demo"></p>
<p>Finding the index of the player with specific rank points.</p>
<script>
var points = [100, 150, 200, 250, 300, 400];
function topRank(points) {
return points == 200;
}
function display() {
document.getElementById("demo").innerHTML = "index = "+points.findIndex(topRank);
}
</script>
</body>
আউটপুট

উপরে, "ফলাফল" -
বোতামে ক্লিক করুন
