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

জাভাস্ক্রিপ্টে একাধিক স্ট্রিং দিয়ে অ্যারে ফিল্টার করা

একাধিক স্ট্রিং দিয়ে অ্যারে ফিল্টার করতে for লুপ সহ indexOf() ব্যবহার করুন। নিচে কোডটি দেওয়া হল:

উদাহরণ

var details = [
  'My first Name is John and last Name is Smith',
  'My first Name is John and last Name is Doe',
  'Student first Name is John and last Name is Taylor'
];
var isPresent;
var records = [];
var matchWords = ['John', 'Doe'];
for (var index = 0; index < details.length; index++){
  isPresent = true;
  for (var outer = 0; outer< matchWords.length; outer++) {
    if (details[index].indexOf(matchWords[outer]) === -1) {
      isPresent = false;
      break;
    }
  }
  if (isPresent){
    records.push(details[index]);
  }
}
console.log(records)

উপরোক্ত প্রোগ্রাম চালানোর জন্য নিচের কমান্ডটি ব্যবহার করুন:

node fileName.js

এখানে, আমার ফাইলের নাম demo151.js।

আউটপুট

এটি নিচের আউটপুটটি তৈরি করবে:

PS C:\Users\Amit\JavaScript-code> node demo151.js
[ 'My first Name is John and last Name is Doe' ]
  1. জাভাস্ক্রিপ্টে একাধিক চেকবক্স শর্তের উপর ভিত্তি করে অ্যারে ফিল্টার করা

  2. জাভাস্ক্রিপ্টে অবজেক্টের অ্যারেতে প্রোপার্টি নাম রিপ্লেস করা

  3. জাভাস্ক্রিপ্টে একাধিক মান দিয়ে অ্যারে এলিমেন্ট খুঁজে বের করা

  4. জাভাস্ক্রিপ্টে ফ্ল্যাট অবজেক্ট অ্যারেকে ট্রি-তে রূপান্তর