

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
JavaScript filter an array of strings, matching case insensitive substring?
Let’s first create array of strings −
let studentDetails = [ {studentName: "John Smith"}, {studentName: "john smith"}, {studentName: "Carol Taylor"} ];
Now, match case insensitive substring, use the filter() and the concept of toLowerCase() in it. Following is the code −
Example
let studentDetails = [ {studentName: "John Smith"}, {studentName: "john smith"}, {studentName: "Carol Taylor"} ]; var searchName="John Smith" console.log(studentDetails.filter(obj => obj.studentName.toLowerCase().indexOf(searchName.toLowerCase()) >= 0));
To run the above program, you need to use the following command;
node fileName.js.
Here, my file name is demo55.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo55.js [ { studentName: 'John Smith' }, { studentName: 'john smith' } ]
- Related Questions & Answers
- How to perform Case Insensitive matching with JavaScript RegExp?
- How to do case insensitive string comparison of strings in JavaScript
- JavaScript Count characters case insensitive
- Python – Filter Similar Case Strings
- JavaScript filter array by multiple strings?
- JavaScript Check for case insensitive values?
- Java Program to sort an array in case-insensitive order
- How to use case-insensitive switch-case in JavaScript?
- MySQL case-insensitive DISTINCT?
- Forming and matching strings of an array based on a random string in JavaScript
- Case-insensitive Dictionary in C#
- Case insensitive search in Mongo?
- Matching strings for similar characters - JavaScript
- Filter an object based on an array JavaScript
- Case-insensitive string comparison in C++
Advertisements