
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
JavaScript filter array by multiple strings?
To filter array by multiple strings, use for loop along with indexOf(). Following is the code −
Example
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)
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo151.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo151.js [ 'My first Name is John and last Name is Doe'
- Related Articles
- JavaScript filter an array of strings, matching case insensitive substring?
- JavaScript example to filter an array depending on multiple checkbox conditions.
- Filter array of objects by a specific property in JavaScript?
- Filter array with filter() and includes() in JavaScript
- Filter one array with another array - JavaScript
- Filter array based on another array in JavaScript
- Filter JavaScript array of objects with another array
- Python - Filter Supersequence Strings
- Splitting strings based on multiple separators - JavaScript
- Remove elements from array using JavaScript filter - JavaScript
- How to find elements of JavaScript array by multiple values?
- Sort an array of objects by multiple properties in JavaScript
- JavaScript in filter an associative array with another array
- Filter by several array elements in MongoDB?
- Python Program to Join strings by multiple delimiters

Advertisements