Last active
February 21, 2020 07:51
-
-
Save alegut/215e3d1862841b2161c53965a20b1a23 to your computer and use it in GitHub Desktop.
Search in array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const employees = [ | |
{ id: 101, name: 'john', group: 'tech-lead' }, | |
{ id: 102, name: 'sam', group: 'associate' }, | |
{ id: 103, name: 'danny', group: 'senior associate' }, | |
{ id: 104, name: 'ketty', group: 'senior associate' }, | |
{ id: 105, name: 'mili', group: 'junior' }, | |
{ id: 106, name: 'mouli', group: 'senior associate' }, | |
{ id: 107, name: 'George', group: 'senior associate' } | |
]; | |
// Case-Insensitive | |
let res = employees.filter(it => new RegExp('li', "i").test(it.name)); | |
// Case-sensitive | |
let res = users.filter(it => it.name.includes('li')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment