Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I search an object for certain object properties case insensitively?

I receive an object from the Gmail API and I need to extract certain properties. The problem is that sometimes the object property I am looking for in the original object is written in capital letters and sometimes not (e.g. Content-Id instead of Content-ID).

var ob = headers.find(({ name }) => name == "Content-ID"); will not find all variations.

What can I do to find all of them (case insensitive search)?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thanks a lot.

>Solution :

use toLowerCase() method.

The toLowerCase() method returns the calling string value converted to lower case.

When your code would be the following:

var ob = headers.find(({ name }) => name.toLowerCase() == "content-id");
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading