Syntax, Parameter and Return Value
Syntax:
_.lowerFirst([string=''])
Parameters:
[string=''] (string): The string to convert.
Return Value:
(string) - Returns the string with the first character in lowercase.
Examples
Lowercasing the First Character of a String:
JavaScript
var _ = require('lodash');
var text = 'Hello world';
console.log(_.lowerFirst(text));

You can also try this code with Online Javascript Compiler
Run Code
Output:
'hello world'
Demonstrates converting the first character of a string to lowercase.
Formatting for Camel Case:
JavaScript
var title = 'TitleCase';
console.log(_.lowerFirst(title));

You can also try this code with Online Javascript Compiler
Run Code
Output:
'titleCase'
Shows converting the first character to lowercase for camelCase formatting.
Handling Strings with Leading Spaces:
JavaScript
var phrase = ' Leading space';
console.log(_.lowerFirst(phrase));

You can also try this code with Online Javascript Compiler
Run Code
Output:
' leading space'
An example of how _.lowerFirst() handles strings with leading spaces.
Standardizing User Input:
JavaScript
var userInput = 'USERNAME';
console.log(_.lowerFirst(userInput));

You can also try this code with Online Javascript Compiler
Run Code
Output:
'uSERNAME'
Demonstrates adjusting user input to start with a lowercase letter.
Frequently Asked Questions
How does _.lowerFirst() handle non-alphabetic characters?
_.lowerFirst() only affects the first character if it is alphabetic. Non-alphabetic characters at the beginning of the string are left unchanged.
Does _.lowerFirst() affect the rest of the string?
No, _.lowerFirst() only changes the case of the first character. The rest of the string remains in its original state.
Can _.lowerFirst() be used for non-English text?
_.lowerFirst() works with any alphabetic character that has a lowercase equivalent. However, it may not behave as expected with characters or scripts that do not follow the same upper/lowercase rules as English.
Conclusion
Lodash's _.lowerFirst() method is a straightforward tool for converting the first character of a string to lowercase, useful for text formatting and complying with specific naming conventions like camelCase.
You can refer to our guided paths on the Coding Ninjas. You can check our course to learn more about DSA, DBMS, Competitive Programming, Python, Java, JavaScript, etc.
Also, check out some of the Guided Paths on topics such as Data Structure and Algorithms, Competitive Programming, Operating Systems, Computer Networks, DBMS, System Design, etc., as well as some Contests, Test Series, and Interview Experiences curated by top Industry Experts.