একাধিক স্ট্রিং দ্বারা অ্যারে ফিল্টার করতে, 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'