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)?

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");

Leave a Reply