xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

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, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2021-01-28 23:00  xgqfrms  阅读(134)  评论(4编辑  收藏  举报