JavaScript Lodash filter ignore case lodash filter ignore case,lodash filter exclude

is there a way of case-insensitive filter with lodash? I tried this (see below), but this works only partly (when the user input is also lowercase). Another problem is here after one search all the characters are in lower case.

I want to 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!

Answer:1

This approach worked out great for me:

this.approverEntities = _.filter(searchData, (a) =>  {return new RegExp(a.email, 'i').test(query)});

The one caveat is that if the a.email contains any special characters the regex expression will process it as regex tokens (e.g. parenthesis, brackets, etc.). This solution will handle special characters regardless...

this.approverEntities = _.filter(searchData, (a) =>  {return a.email.toLowerCase() == query.toLowerCase()});
Answer:2

This is how I did a case insensitive filter while also only requiring a substring:

this.approverEntities = filter(searchData, function(a){
   return a.email.toLowerCase().indexOf((query).toLowerCase()) !== -1;
}
Answer:3

I cannot seem to get the imagetools plugin to load with TinyMCE 4.2.5. I have downloaded TinyMCE 4.2.5 and installed it in my root site /tinymce. Here's my code: <script src="~/tinymce/tinymce....

I cannot seem to get the imagetools plugin to load with TinyMCE 4.2.5. I have downloaded TinyMCE 4.2.5 and installed it in my root site /tinymce. Here's my code: <script src="~/tinymce/tinymce....

  1. tinymce image tools
  2. tinymce image tools plugin
  3. tinymce image tools not working
  4. tinymce image tools plugin download

Im using cheerio to do some scraping and want to access the head js element on a page (notably instructables). I can access it but it comes back as function. So using this: console.log($('script')...

Im using cheerio to do some scraping and want to access the head js element on a page (notably instructables). I can access it but it comes back as function. So using this: console.log($('script')...

With promises, we can use a variant of .then to split up the chain when an error occurs. Here is an example using fetch fetch('http://website.com').then( // Perform some logic (response) => ...

With promises, we can use a variant of .then to split up the chain when an error occurs. Here is an example using fetch fetch('http://website.com').then( // Perform some logic (response) => ...

How can I check if a div has a data-attribute and remove the div if it has that data-attribute, the opposite works like this: $("div[id='foo']").not('[data-type=edit]').remove();

How can I check if a div has a data-attribute and remove the div if it has that data-attribute, the opposite works like this: $("div[id='foo']").not('[data-type=edit]').remove();

  1. jquery check data attribute
  2. jquery check data attribute value
  3. jquery check data attribute exists
  4. jquery check data type
  5. jquery check data value
  6. jquery check data exists
  7. jquery check data in array
  8. jquery check data
  9. jquery check data empty
  10. jquery check data-toggle
  11. jquery check data attribute empty
  12. jquery check data attr
  13. jquery check data before submit
  14. jquery check data is null
  15. jquery check data length
  16. jquery check data-role
  17. jquery check data element
  18. jquery data check if exists
  19. jquery check if data attribute exists
  20. jquery check has data attribute