javascript - Lodash filter ignore case -
is there way of case-insensitive filter lodash? tried (see below), works partly (when user input lowercase). problem here after 1 search characters in lower case.
i want filter regardless of how (lower case or upper).
filter(q: string) { let query = q.trim(); let searchdata = []; searchdata = clone(this.data); searchdata = searchdata.map((entity) => { entity.email = entity.email.tolowercase(); return entity; }); if (query) { this.approverentities = filter(searchdata, (a) => a.email.indexof(query) >= 0); } else { this.approverentities = this.data; } }
thanks in advance!
you can use filter(), method(), , case-insensitive regular expression:
_.filter(searchdata, _.method('email.match', /foo/i));
or, if search term dynamic:
const filtercaseinsensitive = (search, searchdata) => _.filter(searchdata, _.method('email.match', new regexp(search, 'i'));
Comments
Post a Comment