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, 禁止轉載 🈲️,侵權必究⚠️!


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章