capitalise except and javascript code example
Example 1: javascript capitalize
myString = 'the quick green alligator...';
myString.replace(/^\w/, (c) => c.toUpperCase());
myString = ' the quick green alligator...';
myString.trim().replace(/^\w/, (c) => c.toUpperCase());
Example 2: capitalize first carater js
const capitalize = (s) => {
if (typeof s !== 'string') return ''
return s.charAt(0).toUpperCase() + s.slice(1)
}
capitalize('flavio') //'Flavio'
capitalize('f') //'F'
capitalize(0) //''
capitalize({}) //''