toLowerCase() method

The toLowerCase() string method in Apps Script is used to convert all the characters in a string to lowercase letters. This method returns a new string with all the characters converted to lowercase.

For example, suppose we have a string variable name that contains the name “JOHN”. We can convert it to lowercase using the toLowerCase() method as follows:

var name = "JOHN";
var lowerCaseName = name.toLowerCase();
Logger.log(lowerCaseName);

This will output “john” in the logs.

Another example of using toLowerCase() method is to check if a given input string contains a specific keyword regardless of its case. We can convert both the input string and the keyword to lowercase before comparing them to ensure that the search is case-insensitive:

var inputString = "This is a sample sentence";
var keyword = "sample";
if (inputString.toLowerCase().includes(keyword.toLowerCase())) {
  Logger.log("Keyword found!");
} else {
  Logger.log("Keyword not found.");
}

This code will output “Keyword found!” in the logs since the keyword “sample” is present in the input string, regardless of the case of the characters.