781 B
781 B
title, tags, cover, firstSeen, lastUpdated
| title | tags | cover | firstSeen | lastUpdated |
|---|---|---|---|---|
| Decapitalize string | string | blog_images/forest-balcony.jpg | 2018-01-11T11:58:40+02:00 | 2020-11-01T20:50:57+02:00 |
Decapitalizes the first letter of a string.
- Use array destructuring and
String.prototype.toLowerCase()to decapitalize first letter,...restto get array of characters after first letter and thenArray.prototype.join()to make it a string again. - Omit the
upperRestargument to keep the rest of the string intact, or set it totrueto convert to uppercase.
const decapitalize = ([first, ...rest], upperRest = false) =>
first.toLowerCase() +
(upperRest ? rest.join('').toUpperCase() : rest.join(''));
decapitalize('FooBar'); // 'fooBar'
decapitalize('FooBar', true); // 'fOOBAR'