Learn Javascript String examples | Typescript

In this blog post, learn Frequently used String examples in javascript/typescript.

String examples in typescript and javascript You can check my other post on Javascript check substring exists in a String

How to make the first letter a string an upper case?

In some cases, We need to display the String word in uppercase. Its cover capitalizes the first character of a string.

function captialFirstLetterString(string) {  
    return string.charAt(0).toUpperCase() + string.slice(1);  
console.log(captialFirstLetterString('this is test'))  

Output is

How to capitalize the first letter of every word of a string?

function captialFirstLetterEveryWordString(string) {  
    return string.toLowerCase()  
    .split(' ')  
    .map((s) => s.charAt(0).toUpperCase() + s.substring(1))  
    .join(' ');  
var text = "Newyork city test example";  

Output is

Newyork City Test Example  

How to find the String size in bytes

Using Blob object, pass string object which returns the size of bytes of a string.

console.log(new Blob(['kiranbabu']).size) //9  

String toLowerCase example

toLowerCase() method of a string object converts the string into lowercase

console.log(ConvertUppercase('Kiran')) // kiran   
function ConvertUppercase(str) {  
    return str.toLowerCase()  

String toUpperCase example

toUpperCase() method of a string object converts the string in uppercase

console.log(ConvertUppercase('kiran')) // KIRAN  
function ConvertUppercase(str) {  
    return str.toUpperCase()  

Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts
You'll get a notification every time a post gets published here.