Lodash _.lowerCase method

I am a beginner to Lodash and I want to convert the string ‘AnotherPost’ to string ‘anotherpost’. There’s no gap between another and post. But when I use

let title = _.lowerCase('AnotherPost');

console.log(title);
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js" integrity="sha512-WFN04846sdKMIP5LKNphMaWzU7YpMyCU245etK3g/2ARYbPK9Ub18eG+ljU96qKRCWh+quCY7yefSmlkQw1ANQ==" crossorigin="anonymous"></script>

It logs the string ‘another post’ with the space which I don’t want. Can anyone help me with this?

Answer

The _.lowerCase() method converts a string to lower case with spaces between the words.

Use to Lodash’s _.toLower() or the JS String.toLowerCase():

console.log(_.lowerCase('AnotherPost')); // another post

console.log(_.toLower('AnotherPost')); // anotherpost

console.log('AnotherPost'.toLowerCase()); // anotherpost
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js" integrity="sha512-WFN04846sdKMIP5LKNphMaWzU7YpMyCU245etK3g/2ARYbPK9Ub18eG+ljU96qKRCWh+quCY7yefSmlkQw1ANQ==" crossorigin="anonymous"></script>

Leave a Reply

Your email address will not be published. Required fields are marked *