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.
CodePudding user response:
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");