javascript

How to Capitalise First Letter in String Using Lodash


In this article, you will learn how to capitalise first letter using Lodash.

Let’s say you have a string variable named ‘a’ with value “code-source.tempurl.host”.

// Import Lodash library
import _ from "lodash";

var a = "code-source.tempurl.host";

In order to capitalise first letter in string using Lodash, you can use the _.capitalize() method.

// Import Lodash library
import _ from "lodash";

var a = "code-source.tempurl.host";

console.log(_.capitalize(a));

Note: The _.capitalize() method functions by converting the first letter of a string to uppercase and the others to lowercase.


Share on social media

//