javascript-lodashHow do I capitalize a string using Lodash in JavaScript?
Using Lodash in JavaScript, we can capitalize a string by using the _.startCase() method. This method will take a string and capitalize the first letter of each word.
Example
const str = 'hello world';
const result = _.startCase(str);
console.log(result);
Output example
Hello World
The _.startCase() method takes a string as an argument and returns a new string with the first letter of each word capitalized. It will also remove any underscores or hyphens in the string and replace them with spaces.
For example, if we have a string 'hello_world', the _.startCase() method will return 'Hello World'.
We can also use the _.upperCase() method to capitalize the entire string. This method takes a string as an argument and returns a new string with all the letters in uppercase.
Example
const str = 'hello world';
const result = _.upperCase(str);
console.log(result);
Output example
HELLO WORLD
Helpful links
More of Javascript Lodash
- How do lodash and underscore differ in JavaScript?
- How do I use Lodash to sort an array of objects by a specific property in JavaScript?
- How do I use yarn to install and use lodash in a JavaScript project?
- How can I use Lodash's xor function to manipulate JavaScript objects?
- How can I use Lodash to find and update an object in a JavaScript array?
- How can I use Lodash to split a string in JavaScript?
- How do I use Lodash to remove null values from an object in JavaScript?
- How can I compare the usage of lodash's foreach to the native JavaScript foreach loop?
- How can I use Lodash to create a unique array in JavaScript?
- How can I check for undefined values in JavaScript using Lodash?
See more codes...