745 B
745 B
title, type, tags, cover, dateModified
| title | type | tags | cover | dateModified | |
|---|---|---|---|---|---|
| Decapitalize string | snippet |
|
forest-balcony | 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'