কম্পিউটার টিউটোরিয়াল

জাভাস্ক্রিপ্ট Array.findIndex() ফাংশন

জাভাস্ক্রিপ্টের findIndex() মেথড শর্ত পূরণ করা প্রথম এলিমেন্টের ইনডেক্স রিটার্ন করতে ব্যবহৃত হয়।

সিনট্যাক্স:

array.findIndex(function(currentValue, index, arr), thisValue)

উদাহরণ

<!DOCTYPE html>
<html>
<body>
  <h2>Rank</h2>
  <button onclick="display()">Result</button>
  <p id="demo"></p>
  <p>সর্বোচ্চ র‍্যাঙ্ক পেয়ে খেলোয়াড়ের ইনডেক্স খুঁজছি।</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>

আউটপুট

"Result" বাটন ক্লিক করলে ইনডেক্স দেখাবে।

উদাহরণ ২ (নির্দিষ্ট পয়েন্ট)

<!DOCTYPE html>
<html>
<body>
  <h2>Rank</h2>
  <button onclick="display()">Result</button>
  <p id="demo"></p>
  <p>নির্দিষ্ট র‍্যাঙ্ক পয়েন্টের ইনডেক্স খুঁজছি।</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>
  1. জাভাস্ক্রিপ্ট array.toLocaleString() ফাংশন

  2. জাভাস্ক্রিপ্ট Array findIndex() ফাংশন

  3. জাভাস্ক্রিপ্ট Array some() ফাংশন

  4. জাভাস্ক্রিপ্টে ফাংশন রিটার্ন করা অ্যারে অ্যাক্সেস করা