JavaScript Code


How to check if string starts with a lowercase letter using JavaScript?


Check if string starts with lowercase

Given a string, check if the string starts with a lowercase letter using JavaScript.

Solution

To check if a string starts with a lowercase letter using JavaScript, get the first character of the string, and check if this character is same as that of the lowercase version of it. If both are same, then our string starts with a lowercase letter.

Program

1. Given string is str. Check if string str starts with lowercase letter.

str = "hello world";

if ( str[0] === str[0].toLowerCase() ) {
    console.log('string starts with lowercase');
} else {
    console.log('string does not start with lowercase');
}