js uppercase first letter
js uppercase first letter
const str = `abc`;
str.slice(0, 1).toUpperCase();
// "A"
str.slice(1).toLowerCase();
// "bc"
// js uppercase first letter
// capital / capitalization
const log = console.log;
const AutoUpperFirstIndexLetters = (str = ``, index = 1) => {
return str.slice(0, index).toUpperCase() + str.slice(index).toLowerCase();
}
// test
const str = `abcdefg`;
const result1 = AutoUpperFirstIndexLetters(str);
const result2 = AutoUpperFirstIndexLetters(str, 3);
log(`result1 =`, result1);
// result1 = Abcdefg
log(`result2 =`, result2);
// result2 = ABCdefg
refs
https://www.geeksforgeeks.org/how-to-make-first-letter-of-a-string-uppercase-in-javascript/
©xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/14342323.html
未经授权禁止转载,违者必究!